Re: IDL_Container and garbage collection [message #72107] |
Mon, 09 August 2010 09:43 |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On 8/8/10 1:16 AM, Robbie wrote:
> I've just found an interesting problem with migrating from IDL 7 to
> IDL 8. When an IDL_Container is cleaned up and then all of its
> children are automatically deleted. This means that the reference
> count hits zero and all children are also destroyed.
>
> Example code below:
>
> function obj_create_child
> oParent = obj_new('IDL_Container')
> oChild = obj_new('IDL_Container')
> oParent -> Add, oChild
> help, oChild ; Child Object has not been destroyed yet
> ;;;; oParent -> remove, /ALL ; Workaround - Remove all children before
> garbage collection
> ;;;; obj_destroy, oParent ;;; Pedantic - Destroy the empty heap object
> return, oChild
> end
>
> pro obj_create
> help, obj_create_child() ; Child object is destroyed before it is
> returned because oParent is garbage collected
> end
>
> In many ways the above snippet of code is sloppy because it would
> leave the parent object on heap. Code that performed correct garbage
> collection in IDL 7 should not be affected by this issue.
Yes, I suppose the lesson is that if your pre IDL 8.0 code does not leak
memory already, then it should be fine. If your code does leak memory,
it wont leak memory in IDL 8.0 but it has the potential to not work
correctly anymore.
Mike
--
www.michaelgalloy.com
Research Mathematician
Tech-X Corporation
|
|
|