Group: comp.lang.c++
From: Christopher
Date: Thursday, April 10, 2008 6:38 PM
Subject: Re: destroy singleton?

On Apr 10, 6:26 pm, Ron Eggler wrote:
> Andy Champ wrote:
> > Ron Eggler wrote:

[snip]

> i do initialize pinstance like this:

> GPIOcontrol * GPIOcontrol::instance(GPSData *gpsDataObj)
> {
> if (pinstance==NULL){//if this singleton hasn't been created yet...
> pinstance=new GPIOcontrol(gpsDataObj);
> }
> return pinstance; }

[snip]


1) The singleton was initialized with a GPDData object A, but what if
you call GPIOcontrol::instance() with GPSData object B, in which case
it gives you back the singleton initialized with A???
1a) If you take a parameter during initialization, your object might
not be a candidate for a singleton
1a1) After all, if it is to always exist and there can be only one, it
can only be initialized one way... at least for the life of the
process.
2) Do you not care if an invalid or NULL GPSData object was passed as
a parameter?
3) Since GPSData is being passed in as a pointer, who allocated it?
who is going to destroy it? Is your singleton attempting to destroy it
when someone else already did? Or perhaps it is another global object
whom was destroyed during program exit before the singleton?

Safety Articles | Usenet Groups | Usenet News | Bluegrass