in reply to The number of references to a variable
I tought there was a function in Scalar::Util that returns the refcount of an object, but I couldn't find it. But also in Scalar::Util, you find the weaken function, which lets you pass around weak references. From your description, I think you have a "master" object that holds all "relevant" children, but over time, some of the children become irrelevant yet are kept alive by some references. If you make your master hold strong (normal) references but pass out only weak references, your children will be removed if the master removes them from the list.
Such an approach will have different problems, because weak references can turn into strong references again if you copy them, unfortunately. Maybe another approach would be to (always) ask the master whether a child is still relevant or not ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: The number of references to a variable
by jeanluca (Deacon) on Nov 26, 2007 at 14:25 UTC | |
by ikegami (Patriarch) on Nov 26, 2007 at 17:07 UTC |