K
Kaz Kylheku
Hm, have you ever head cycles? In my long experience I neverJames said:tanix wrote:
[...]
Memory managment is not a problem. You can implement GC, for
any apllication even in assembler. Reference counting is
simple form of gc and works well in c++ because of RAII.
Reference counting doesn't work in C++, because of cycles. And
reference counting is very, very slow compared to the better
garbage collector algorithms.
had cyclic references...
Reference counting can;t be slow because it does not have
to lock all threads
Reference counting blocks the calling thread on an atomic increment
or decrement operation whenever the reference count must be manipulated.
Reference counting generates bus traffic. Whenever a refcount field is
written, the corresponding cache line is now dirty on the local
processor and must be updated to the other processors.
Refcounting forces garbage objects to be visited one by one before they
are reclaimed, in a random order, and possibly more than once! An object
with refcount 42 will in general be visited 42 times before 42
references can be dropped.
Someone recently remarked in the comp.lang.lisp newsgroup that a
a particular historic Lisp implementation, which used reference counting
rather than real GC, sometimes fell into such a long pause in
processing a dropped reference that frustrated programmers would just
reboot the system!!!
See when you drop a refcount on an object and it reaches zero, you are
not done. That object has pointers to other objects, and /their/
references have to be dropped. Refcounting does not eliminate the
fact that a graph is being walked.
But reference counting is the dumbest, slowest way of hunting down garbage.