Re: Passing Pointers -- where to delete them
On Mar 4, 10:45 am, Ian Collins <ian-n...@hotmail.com> wrote:
James Kanze wrote:
On Mar 3, 7:29 pm, Ian Collins <ian-n...@hotmail.com> wrote:
I guess that depends whether you allow your singletons to have
public constructors and destructors.
By definition, a singleton doesn't have public constructors or
destructors, at least as I understand the pattern. (At least as
I use and understand the word, singleton refers to a specific
pattern, and not to just any class which happens to be present
only once.) But that's not really the issue. My test harness
ensures that any memory allocated within the test has been freed
at the end of the test. If the first call to the instance()
function of the singleton is within the test, any memory
allocated by the creation of the singleton will appear as a leak
at the end of the test.
I guess we bent the rules for our singleton objects to enable
then to be created and destroyed in tests. The single
instance is enforced through a base class template with a
static member pointer.
The problem with this is that you're no longer testing the code
you actually use.
This is compared to NULL (in an assert) and set in the
object's constructor and deleted in the destructor.
I use cppUnit, creating and deleting singletons in the setUp()
and trearDown() methods.
Doesn't cppUnit support tests using separate processes? If not,
that sounds seriously limiting.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34