Releasing COM Objects

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Releasing COM Objects

Ingo Blank
Hi,

have COM instances to be freed explicitely by #Release via
#finalize or is it done automatically ?

I assume that it is done automatically because I got GPFs when
using a #finalize method, but I'm not sure.

Thanks
Ingo


Reply | Threaded
Open this post in threaded view
|

Re: Releasing COM Objects

Bill Schwab
Ingo,

> have COM instances to be freed explicitely by #Release via
> #finalize or is it done automatically ?
>
> I assume that it is done automatically because I got GPFs when
> using a #finalize method, but I'm not sure.

COM interface pointers are cleaned up automatically via finalization.
There's actually a little more to it, because finalization takes time to
happen (it runs at a low priority, so it might not happen for a "very" long
time).  Hence you will find that COM interface pointers are also cleaned up
on system shutdown; see #onExit.

It's just a hunch, but, I'm guessing that the GPFs were the result of
something you or Dolphin tried to do after you explicitly finalized an
interface pointer.  It's legal to free objects, but, only if you are certain
that they won't be used after that point; when in doubt, it's best to let
Dolphin handle it. For example, explicit cleanup (of GDI objects) becomes
(very) necessary for graphics-intensive apps running on Win9x.  Unless your
COM objects are expensive, you might do well to let them go away on their
own, or perhaps arrange to grab one before a tight loop and use it
throughout rather than creating/discarding lots of instances inside the
loop??

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Releasing COM Objects

Blair McGlashan
In reply to this post by Ingo Blank
Ingo

You wrote in message news:3b0d8c43$0$32217$[hidden email]...
>
> have COM instances to be freed explicitely by #Release via
> #finalize or is it done automatically ?
>
> I assume that it is done automatically because I got GPFs when
> using a #finalize method, but I'm not sure.

It is done automatically. You should never send #finalize messages yourself.
Don't send #Release either since this will remove the reference count
without detaching the pointer and so a double free will occur when the
interface pointer is subsequently finalized by the system.

You can send #free where you are sure that the object/interface is going out
of scope. In the case of a COM object it would be wise to do this only when
the interface is queried and discarded within the same method.

For further details on the pattern we use for lifecyle management see
http://www.object-arts.com/wiki/html/Dolphin/ObjectLiberationStrategy.htm

Regards

Blair


Reply | Threaded
Open this post in threaded view
|

Re: Releasing COM Objects

Blair McGlashan
"Blair McGlashan" <[hidden email]> wrote in message
news:9eltmn$379q$[hidden email]...
> ...
> For further details on the pattern we use for lifecyle management see
> http://www.object-arts.com/wiki/html/Dolphin/ObjectLiberationStrategy.htm

Sorry that should have been.

http://www.object-arts.com/Lib/EducationCentre4/htm/objectliberationstrategy
.htm

Regards

Blair