Re: Question about the object lifecycle [message #68657] |
Sat, 07 November 2009 15:55 |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
M. Katz writes:
> Within complex graphic objects, I often add objects to a main model
> like this
>
> self.oModel = obj_new('IDLgrModel')
> self.oModel -> Add, obj_new('IDLgrPolygon', . . .)
>
> I don't keep an explicit reference to the IDLgrPolygon object in this
> case because I don't need it.
>
> My question is: What happens to the IDLgrPolygon once I destroy the
> parent object? My Cleanup method explicity destroys the self.oModel.
> So what becomes of the orphaned IDLgrPolygon? Will it go into heap
> limbo and ultimately be recycled? Or will it take up space until the
> IDL session is reset? I can see from a quick test using HELP that once
> the IDLgrModel is destroyed, the reference to the child object becomes
> <ObjHeapVar2>, like that.
>
> As a best-practice, should I be keeping the references to every object
> I create in this way, so I can explicitly destroy them in the Cleanup
> method?
A model object is a subclassed IDL_Container object, so any
thing you add to the model is destroyed when the model is
destroyed. So no reason to keep references to objects you
add directly to a model. It is the other objects (e.g, font objects
that you add to text objects that you add to a model object
you have to watch out for). Those can bite you. Always
run your program, exit, and then type Help, /Heap before
you give your program to your boss. You will save yourself
a LOT of embarrassment. Take it from me. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|