IDL_Container and garbage collection [message #72112] |
Sun, 08 August 2010 00:16 |
Robbie
Messages: 165 Registered: February 2006
|
Senior Member |
|
|
Hi,
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.
Robbie
|
|
|