Re: Thread-safe reference counts.
On 30 mar, 02:29, "Chris Thomasson" <cris...@comcast.net> wrote:
"James Kanze" <james.ka...@gmail.com> wrote in message
news:c0da8427-0f37-4505-87d4-730f58f3adce@59g2000hsb.googlegroups.com...
On 28 mar, 23:56, "Chris Thomasson" <cris...@comcast.net>
wrote:
"Jon Harrop" <use...@jdh30.plus.com> wrote in message
news:13uqrk9au723v0d@corp.supernews.com...
jason.cipri...@gmail.com wrote:
I have some code where objects are dynamically allocated by
some thread, and then used by multiple threads and freed
when they are no longer needed. I think that reference
counting is the most appropriate way to handle this in my
situation.
A concurrent garbage collector is the appropriate way to
handle that situation.
Why? There are many different ways to handle lifetime management.
Just to make it clear: the original posting talked about memory
management, not object lifetime management. From the way it was
presented, it more or less sounded like object lifetime had no
significance (often the case). In which case, garbage
collection is fine. But garbage collection has nothing to do
with object lifetime (which, when significant, still must be
managed, garbage collection or not).
GC does indeed detect when an object is not being referenced
by anything (e.g., in a quiescent state). IMHO, this is a
_very_ import part of lifetime management because you cannot
terminate an objects life if its being used by something else.
Garbage collection detects when an object can no longer be
referred to. Obviously, in this case, it's lifetime has ended,
since there is no longer any way to end it otherwise. But
that's about it---garbage collection will not collect the memory
underneath the object that is still alive. Provided, of course,
that there are not errors in the code, and you've lost the last
pointer to the object before its lifetime has ended. But that
has nothing to do with object lifetime per se.
Most objects have indeterminate lifetime, and it doesn't matter.
If an object has determinate lifetime, however, you have to
manage it, garbage collection or no. Garbage collection does
NOT manage object lifetime; it only manages memory.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34