I would like some confirmation about this questions:
When do I need to increase an objects reference count by an implicit call to AddRef?

Until now I think at:
IUnknown -> QueryInterface
IClassFactory -> CreateInstance

What about Get / Set functions inside interfaces, like IOLEObject -> GetClientSite, which return
an interface, should these also call AddRef inside GetClientSite?
Posted on 2003-06-11 09:08:06 by beaster
if you return a pointer you should do AddRef first (as in GetClientSite)
If a pointer is supplied as a parameter, the called function has to do the AddRef (as in SetClientSite)
Posted on 2003-06-11 12:07:13 by japheth
thanks, I will review my interfaces.

I had a problem, that occured since I free allocated object structures inside IUnknown->Release if reference count is zero. This was no problem with Win95, but with Win2000, Win2K seems to handle
the reference counters more correctly, so if I miss one add, the count gets wrong and I free the object too early, so Windows tries to call methods on an already freed object.
Posted on 2003-06-12 06:51:09 by beaster
Hi beaster,

that's really one of the most common and time consuming problems. In debug versions of my programs I "clear" memory of heap item with AAh before freeing it. Thats useful for Win9x, as you have already mentioned.

Posted on 2003-06-12 07:32:04 by japheth