This discussion is archived
4 Replies Latest reply: Sep 6, 2010 12:40 PM by jtahlborn RSS

C++ style reference-counted pointers?

843798 Newbie
Currently Being Moderated
In C++ there is (though not all that commonly used) a thing called a reference-counted pointer. It allows multiple objects to reference a common object without forcing the burden of managing the memory utilization of the object on one referrer. Any one can invoke its destructor; if there are multiple referers the reference count is simply decremented. The object's memory is freed only when the count goes to zero. (Thank Pengie for automatic garbage collection!)

There is a nice side effect for caches that use them. A cache manager can tell that no one is using a cache element if the reference count is zero.

Can such a thing be done using Java References? If so please point me to a discussion.

TIA