That was an interesting question. I've used one under ARC and it does, but I 
thought .. let's check with the documentation. 

Well the documentation says nothing about ARC at all until you get to the end 
where the Revision History table is and that says .. 

2013-08-08      Noted that NSPointerArray is not suitable for subclassing.
2012-07-23      Updated for OS X v10.8.
2011-09-16      Noted that this class doesn't support weak references under ARC.
2009-03-04      Clarified behavior in fast enumeration.
2007-01-06      New document that describes the mutable collection that can 
hold NULL values.
So there's a note from 2011 saying no it doesn't, but that note's not there, 
nor is there another note saying that note's not there any more. That sent me 
looking to guess what was 'Updated for OS X v10.8' which ended up here 
https://developer.apple.com/library/mac/releasenotes/Foundation/RN-FoundationOlderNotes.
 

If you read that note enough times you'll find that 
NSPointerFunctionsZeroingWeakMemory was deprecated and replaced with 
NSPointerFunctionsWeakMemory (removal of the word weak). The former function, 
with 'Zeroing' in it, held zeroing weak pointers under GC and non-retained 
pointers under MRC and I'm guessing was the subject of the ARC note which isn't 
there any more. The new function, without the word 'Zeroing' "causes zeroing 
weak behavior under manual reference counting, automatic reference counting, 
and garbage collection". ie the new one without the word 'Zeroing' zeros in 
more cases than it did before. 

Finally under "NSPointerArray zeroing weak changes" it tells you the old 
functions which used NSPointerFunctionsZeroingWeakMemory have been deprecated 
and the replacements, eg +weakObjectsPointerArray, use the new 
NSPointerFunctionsWeakMemory function. 

So from all that I deduce that if you are using the replacement functions and 
not the deprecated ones, you have zeroing weak memory under ARC (and GC but 
that's already deprecated). 

I do sometimes wish the revision history was a bit more verbose, or at least 
there was a way to see the various revisions of the document to see what 
actually changed. 


> On 9 Aug 2014, at 2:53 pm, Jonathan Mitchell <[email protected]> wrote:
> 
> 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 protected])
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/rols%40rols.org
> 
> This email sent to [email protected]

_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to