-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);
In reply to Re: return weak reference
by ikegami
in thread return weak reference
by flipper
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |