in reply to Catching an object going out of scope

If I understand you correctly, you can store a reference to $self in each My::Class::Temp object. This will prevent the current garbage collector to claim the space of the object once it leaves scope.

The problem is how do you destroy this object later... I guess you can't, because you no longer have references to it (it went out of scope).

The answer to this last point, would be to keep a weak reference to the object. You should have good enough reasons to outweight the general ickiness in doing this tough :)

You could then have a custom function that destroys the circular reference and then destroys the weak reference. At this stage, the garbage collector can reclaim your object's space as it went completely out of scope.

Hope this helps.

  • Comment on Re: Catching an object going out of scope