August 25, 2013
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
August 25, 2013
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