Re: [Dev-C++] singleton pattern implementation.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Chris M. <lor...@gm...> - 2007-09-28 00:06:38
|
On 9/27/07, Younes Ouadi <ou...@ei...> wrote:
> Hello,
>
> The question to ask: is there a need to release the memory reserved for
> the singleton? In other words:
> * Does the singleton lives from the moment where is is created (the
> first call to newInstance()) till the end of your application (no need
> to release it)?
> * Or should it disappear before the end of the application (the related
> memory should be released)?
>
> If the answer is No, and this is my feeling, just forget about it. When
> your application will end, the system will get back its memory
> automatically.
What planet are you living on? Can I move there?
> If for any reason the answer is Yes, then add a member method to your
> class ('deleteInstance' for example) that will:
> * delete the singleton 'delete singleton;'
> * set the singleton to NULL: 'singleton = NULL;' (by the way, your can
> forget about 'instanceFlag' and test only on 'singleton' value: NULL
> means allocate, Not NULL, don't allocate)
>
> And call this method at the moment where you like to release the memory
> linked to the singleton.
>
> Nota Bena: don't mix allocate/free with new/delete. They are completely
> different and doesn't like each other.
There are some collisions between them, yes.
--
Registered Linux Addict #431495
If You Know What's Good For You, You'll Install Linux
John 3:16!
|