• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
-[NSGarbageCollection disableCollectorForPointer:] ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

-[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


  • Follow-Ups:
    • Re: -[NSGarbageCollection disableCollectorForPointer:] ?
      • From: "Ken Ferry" <email@hidden>
  • Prev by Date: Re: Animating view transitions with Core Animation (problems with BasicCocoaAnimations sample)
  • Next by Date: Re: EXC_BAD_ACCESS with NSAutoReleasePool, NSThread and NSThreadWillExitNotification
  • Previous by thread: Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning
  • Next by thread: Re: -[NSGarbageCollection disableCollectorForPointer:] ?
  • Index(es):
    • Date
    • Thread