-[NSGarbageCollection disableCollectorForPointer:] ?
-[NSGarbageCollection disableCollectorForPointer:] ?
- Subject: -[NSGarbageCollection disableCollectorForPointer:] ?
- From: Michael Link <email@hidden>
- Date: Tue, 14 Oct 2008 23:43:31 -0500
I have a situation where I create an NSPointerArray on the stack by:
pointers = [NSPointerArray
pointerArrayWithOptions:NSPointerFunctionsStrongMemory|
NSPointerFunctionsOpaqueMemory|NSPointerFunctionsOpaquePersonality];
I then go about adding a few objects a selector and a pointer
(contextInfo that could point to anything even a non-object) to the
pointer array.
I then call:
[[NSGarbageCollector defaultCollector]
disableCollectorForPointer:pointers];
The pointer array is then passed as the contextInfo for another method
(which turns out to be a weak reference), but isn't garbage collected
due to the previous call. The interesting part turns out that the
object at index 0 (NSError* in this case) in the pointer array is
garbage collected (probably because it was a variable in the function
that called us). The pointer array is configured to use strong
references therefore index 0 isn't set to NULL and something else is
located at that memory (sometimes a different object, sometimes
garbage memory).
If I use:
[[NSGarbageCollector defaultCollector] disableCollectorForPointer:
[pointers pointerAtIndex:0]];
nothing bad happens and that object isn't collected.
According to the documentation for disableCollectorForPointer:
shouldn't the pointer array be considered a new root object, and none
of it's pointers collected? Especially since it uses strong references?
--
Michael
_______________________________________________
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