• 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
Re: -[NSGarbageCollection disableCollectorForPointer:] ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -[NSGarbageCollection disableCollectorForPointer:] ?


  • Subject: Re: -[NSGarbageCollection disableCollectorForPointer:] ?
  • From: "Ken Ferry" <email@hidden>
  • Date: Tue, 14 Oct 2008 23:08:13 -0700

Hi Michael,

NSPointerFunctionsStrongMemory|NSPointerFunctionsOpaqueMemory doesn't
make sense. You're meant to specify only one of the memory options and
only one of the personality options.

Due to the way the bitfield work, your invocation is the same as
NSPointerFunctionsOpaqueMemory|NSPointerFunctionsOpaquePersonality.
This is the mode in which the pointer array is completely hands-off.
It acts like a C array.

Try NSPointerFunctionsStrongMemory|NSPointerFunctionsOpaquePersonality.
 That sounds right to me, though I get confused with the pointer
functions too.

-Ken

On Tue, Oct 14, 2008 at 9:43 PM, Michael Link <email@hidden> wrote:
> 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
>
_______________________________________________

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: Michael Link <email@hidden>
References: 
 >-[NSGarbageCollection disableCollectorForPointer:] ? (From: Michael Link <email@hidden>)

  • Prev by Date: Re: NSTask not cleaning up it's threads
  • Next by Date: -decodeBase64 method for NSString: problems
  • Previous by thread: -[NSGarbageCollection disableCollectorForPointer:] ?
  • Next by thread: Re: -[NSGarbageCollection disableCollectorForPointer:] ?
  • Index(es):
    • Date
    • Thread