[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ms-atl
Subject:    Re: Release() in destructor crashes
From:       Jason Whittington <jasonw () DEVELOP ! COM>
Date:       2000-06-30 23:44:08
[Download RAW message or body]


> The statement m_pIChild->Release() crashes with access violation
> 0xc000005.
> I'am not sure why this happens.


Singleton objects should not NOT hold pointers to other objects, especially
if they are being accessed from multiple threads, and even worse if they are
being accessed from multiple apartments.  The issues are almost exactly the
same as FTM objects. Your singleton should store interface pointers in the
GIT. Hopefully this transition will be painful, making you ask why you tried
to use a singleton to being with.  The ATL/DCOM archives are filled to the
rafters with articles saying "Singletons are a poor design decision" and
suggesting alternative designs.

On W2k I guess another solution for the stubborn would be a Singleton marked
ThreadingModel=Neutral.  Then you won't need the GIT.  Still, if you ever
want to port to MTS/COM+ your singleton code will have to be refactored
anyway.

If you're developing a single-threaded EXE server you won't have these
problems, but why would you do that these days?  There's no reason for it.

Jason

----------------------------------------------------------------
Users Guide http://msdn.microsoft.com/workshop/essentials/mail.asp
contains important info including how to unsubscribe.  Save time, search
the archives at http://discuss.microsoft.com/archives/index.html

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic