Re: NSAllocateCollectable() questions
Re: NSAllocateCollectable() questions
- Subject: Re: NSAllocateCollectable() questions
- From: Alastair Houghton <email@hidden>
- Date: Wed, 16 Apr 2008 10:28:00 +0100
On 16 Apr 2008, at 03:29, Michael Ash wrote:
On Tue, Apr 15, 2008 at 4:53 PM, Greg Parker <email@hidden>
wrote:
You don't need a write barrier when erasing GC-scanned memory. The
write
barrier helps the collector see pointers that it might otherwise miss
because it's cheating. It does not help the collector "forget" a
value that
it saw previously. (In particular, the old pointer value might be
gone from
the zeroed location, but without re-scanning everything there's no
way to
know that it doesn't still exist somewhere else.)
If this is the case then how does the collector know that you have
cleared the memory. It seems to me that without a write barrier, the
collector will not see the change and will think that that you
continue to hold the old pointer in this memory.
No. The garbage collector does not use reference counting, and so
your statement is not true. If you overwrite the last pointer to an
object with a nil, the pointed-to object *may* survive the current
garbage collection cycle, but it will not survive the next one.
If you want to understand why, there are a number of books and papers
on the subject, as well as numerous resources on the Internet that
explain how garbage collectors are implemented. One of the best is
Paul R. Wilson's Uniprocessor Garbage Collection Techniques, which you
can find here:
ftp://ftp.cs.utexas.edu/pub/garbage/bigsurv.ps
Cocoa GC is actually a concurrent collector, but if you read through
the parts describing mark-sweep, incremental and generational
collection you will have a good idea what the write barrier does and
doesn't do and why it is needed.
Richard Jones' Garbage Collection Page is also quite good, and he has
written a book on the topic as well:
http://www.cs.kent.ac.uk/people/staff/rej/gc.html
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden