Re: A coding pattern that does not work under Garbage Collection
Re: A coding pattern that does not work under Garbage Collection
- Subject: Re: A coding pattern that does not work under Garbage Collection
- From: Jim Correia <email@hidden>
- Date: Fri, 9 Nov 2007 11:57:13 -0500
On Nov 9, 2007, at 11:47 AM, Rick Hoge wrote:
You kept a (default, no strong or weak modifier) pointer to data
inside the object, but no one kept a pointer to the object, so it
was collected.
So if I had added the __strong modifier to the pointer assignment,
the collector would know not that the memory was still in use?
(Not a GC expert...)
No, I think you're still screwed. Since you can't know how NSData
manages its bucket of bytes, you need to make sure the NSData object
stays around for as long as you want to work with the bytes.
The salient point was that no one kept a reference to the object
which owned the bytes you were pointing at, and when the object got
collected as a result, it's internal storage also went away.
Really not so different from the autorelease case, except there you
were guaranteed the lifetime of the parent autorelease pool. In a GC
world the collector will collect unreferenced objects when it gets
around to it, so you better keep a strong reference to the object for
as long as you need it.
Jim
_______________________________________________
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