Re: How to cleanup an object with a non-modal widget method [message #88109 is a reply to message #88082] |
Thu, 20 March 2014 15:51   |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
David,
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? Thanks, --Wayne
On Wednesday, March 19, 2014 8:23:10 AM UTC-4, David Fanning wrote:
> wlandsman writes:
>
>
>
>> Well, one of the methods of the object creates the widget. So I'd say that the object contains the widget, which is why the widget code refers to self when it needs information from the object (e.g. the top level base ID is stored in self.gui ) I don't have any object reference within the widget method which I can destroy except for self. Thanks, --Wayne
>
>
>
> I'm thinking something like this:
>
>
>
> oAstroMap = obj_new('AstroMap') ;Create the object
>
> oAstroMap.widgetdisplay ;Create the display widget
>
>
>
> So, I write the WidgetDisplay method like this:
>
>
>
> PRO AstroMap::WidgetDisplay
>
> tlb = Widget_Base(Title='MyWidget',UValue=self, $
>
> Kill_Notify='Widget_Cleanup')
>
> .... ; Doesn't matter what widget I store the object in, $
>
> .... ; just that it have a kill callback associated with it.
>
> END
>
>
>
> And, I write Widget_Cleanup like this:
>
>
>
> PRO Widget_Cleanup, widget_that_is_dying
>
> Widget_Control, widget_that_is_dying, Get_UValue=myObject
>
> Obj_Destroy, myObject
>
> END
>
>
>
> 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.")
|
|
|