www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Count of object references?

reply "Bottled Gin" <gin bottled.com> writes:
Hello All

Given a class object, is there a way to find out the number of 
references to it. I have a situation where a container is holding 
an object and I would like to remove the object from the 
container if there is nobody else referencing it.

Is it possible in D?

Regards
- Puneet
Aug 25 2013
parent "bearophile" <bearophileHUGS lycos.com> writes:
Bottled Gin:

 Given a class object, is there a way to find out the number of 
 references to it. I have a situation where a container is 
 holding an object and I would like to remove the object from 
 the container if there is nobody else referencing it.

 Is it possible in D?
What you want is a container that keeps weak references (http://en.wikipedia.org/wiki/Weak_reference ). Currently (I think) there are no weak references in Phobos, but eventually it should be added. Probably somewhere there is some implementation. Bye, bearophile
Aug 25 2013