Re: [Dev-C++] singleton pattern implementation.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2007-09-28 00:11:40
|
Only embedded-system operating systems should/may be unable to reclaim all
memory after a program/task has ended.
However, there are other issues with not calling an object destructor. The
object may contain other resources that are not reclaimable by the OS. For
example, the object may use temporary files that should be removed by the
destructor. Or the object could control aspects of some hardware.
/pwm
On Thu, 27 Sep 2007, Chris Miller wrote:
> 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!
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|