in reply to Re^3: weak-reference set internally
in thread weak-reference set internally

true, but in other cases i may well have created the Foo object outside of the creation of a Bar, and ALSO store it internally within Bar (for ease of use within Bar's methods), hence the reason for the weak-ref.

This is the issue...

Replies are listed 'Best First'.
Re^5: weak-reference set internally
by Corion (Patriarch) on Sep 30, 2010 at 10:02 UTC

    You either need the parent to still be around. Then you need a strong reference. Or it is OK if the parent goes away. Then you need a weak reference.

    If you have a strongly referenced relation between parent and child, you will need to call a special method (like, ->free()) to release the references you hold explicitly. As Perls memory management is based on reference counting, there is no other, implicit way to find out that a set of memory objects is not referenced from anywhere on the outside.

    If you want a bit more sanity in managing such object forests, you can keep a reference to a "master" object for each tree, whose main purpose is to call ->free() on the topmost parent object of that tree.

Re^5: weak-reference set internally
by Anonymous Monk on Sep 30, 2010 at 10:04 UTC
    I can't quite envision a scenario where you need this, but either you want Foo available or you don't. Pick one.