| Re: How to cleanup an object with a non-modal widget method [message #88110 is a reply to message #88109] |
Thu, 20 March 2014 15:57  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Wayne Landsman writes:
> Thanks for this. I think that when destroying an object from a non-modal widget that IDL's automatic garbage collection does not come into play, so that one needs to have proper cleanup methods. And let's just say that my cleanup methods were, um, suboptimal, so it did not appear that the cleanup was working at all. My partial excuse is that automatic garbage collection has made me lazy, but I am also not entirely clear on the concepts.
>
> For example, my map display object includes many other objects which must either be created or passed in via keyword. So my INIT method looks like this:
>
> pro mapdisplay::init,oCoord=oCoord
> if obj_valid(oCoord) then self.oCoord = oCoord else self.oCoord = obj_new('Coord')
>
> Now in the cleanup method, I want to destroy self.oCoord if it was created in the ::INIT, but not if it was passed by keyword. How is the Cleanup method supposed to know which is the case? The only solution I can think of is to add a flag to the object, which can be used by ::CLEANUP
>
> pro mapdisplay::init,oCoord=oCoord
> if obj_valid(oCoord) then begin
> self.oCoord = oCoord
> self.destroy_oCoord = 0
> endif else begin
> self.oCoord = obj_new('oCoord')
> self.destroy_oCoord = 1
> endelse
>
> Is there a better way than this?
Not to my knowledge. This is the way I do it. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
|