• 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
Does NSPointerArray support zeroing weak references under ARC
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Does NSPointerArray support zeroing weak references under ARC


  • Subject: Does NSPointerArray support zeroing weak references under ARC
  • From: Jonathan Mitchell <email@hidden>
  • Date: Sat, 09 Aug 2014 07:53:57 +0100

Does NSPointerArray support zeroing weak references under ARC?

The test below seems to indicate that it does - though this is the sort of thing I often get wrong.

Note that a NULL survives -compact.
Presumably the method is free to not compact in trivial cases - or is there another explanation?

int main(int argc, const char * argv[])
{
NSPointerArray *parray = [NSPointerArray weakObjectsPointerArray];
NSString *value1 = [NSString stringWithUTF8String:"test1"];
[parray addPointer:(__bridge void *)(value1)];

@autoreleasepool {

 NSString *value2 = [NSString stringWithUTF8String:"test2"];
 [parray addPointer:(__bridge void *)(value2)];

 for (id item in parray) NSLog(@"%@", item);

 NSLog(@"Draining pool...");
}

for (id item in parray) NSLog(@"%@", item);


NSLog(@"Compacting...");
[parray compact];
for (id item in parray) NSLog(@"%@", item);

return 0;
}

output:

2014-08-08 17:41:54.982 WeakObjectsPointerArray[22437:303] test1
2014-08-08 17:41:54.984 WeakObjectsPointerArray[22437:303] test2
2014-08-08 17:41:54.985 WeakObjectsPointerArray[22437:303] Draining pool...
2014-08-08 17:41:54.985 WeakObjectsPointerArray[22437:303] test1
2014-08-08 17:41:54.986 WeakObjectsPointerArray[22437:303] (null)
2014-08-08 17:41:54.986 WeakObjectsPointerArray[22437:303] Compacting...
2014-08-08 17:41:54.986 WeakObjectsPointerArray[22437:303] test1
2014-08-08 17:41:54.987 WeakObjectsPointerArray[22437:303] (null)

Thanks

Jonathan












_______________________________________________

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: Does NSPointerArray support zeroing weak references under ARC
      • From: Sean McBride <email@hidden>
    • Re: Does NSPointerArray support zeroing weak references under ARC
      • From: Roland King <email@hidden>
  • Prev by Date: Swift and NSXPCInterface
  • Next by Date: Re: Does NSPointerArray support zeroing weak references under ARC
  • Previous by thread: Re: Swift and NSXPCInterface
  • Next by thread: Re: Does NSPointerArray support zeroing weak references under ARC
  • Index(es):
    • Date
    • Thread