in reply to return weak reference
-X->+---------+ -Y->| Node | -Z->+---------+ | ^ A B v | +---------+ | Node | +---------+
Your initial solution was to weaken "X", "Y" and "Z". That doesn't work because the creation of "Y" and "Z" is done outside of your control. You could weaken "B" instead. If for some reason, you can't do that (e.g. if you don't actually control the creation of those nodes), you could use a wrapper.
The wrapper would has a destructor that deletes "A" or "B", breaking the loop, freeing the nodes. This wrapper has already been written for you: Object::Destroyer.-X->+---------+ +---------+ -Y->| Wrapper |-J->| Node | -Z->+---------+ +---------+ | ^ A B v | +---------+ | Node | +---------+
use Object::Destroyer qw( ); $tree = Object::Destroyer->new($tree);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: return weak reference
by flipper (Beadle) on Sep 02, 2010 at 09:52 UTC | |
by ikegami (Patriarch) on Sep 02, 2010 at 15:32 UTC |