Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Object destruction order is not respected anymore once Global Destruction sets in. Global destruction happens after your main script "falls off the end" (or calls exit) and all END blocks have executed. A way I've used to better localize the memory cycle that keeps objects alive until Global Destruction is to explicitly release the "master object" at the last (executed) line of the program:
If that works and everything gets released properly, this means you have a simple cycle and $object is kept alive somehow. There are some cases of closures that keep your lexical variables alive beyond the main program. One especially nasty case (for me) is:
... but also, creating and handing around other closures might create problems, especially if these closures are kept alive somewhere:
Careful use of Scalar::Util::weaken or careful undeffing of $object within (one-shot) closures might help to locate and eliminate the problem. If all else fails, defensive programming in the destructors also helps (taken from MozRepl::RemoteObject, which has this problem):
In reply to Re: sub DESTROY: Strange ordering of object destruction
by Corion
|
|