[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
NSProxy retain / release
From: |
David Chisnall |
Subject: |
NSProxy retain / release |
Date: |
Thu, 30 Jun 2011 14:57:09 +0100 |
Hi,
I was looking at NSProxy's code, and it seems to store its retain count in an
ivar, rather than using the standard one. Is there a reason for this? It
means that:
- NSProxy uses one word more than it needs to, two more than it needs to in GC
mode
- -retain and -release on NSProxy subclasses are not thread-safe (they don't
use atomic ops)
- -retainCount and NSExtraRefCount give different results (contrary to the
Cocoa behaviour)
David
$ cat proxy.m
#import <Foundation/Foundation.h>
int main(void)
{
[NSAutoreleasePool new];
id p = [NSProxy alloc];
NSLog(@"%d (%d)", (int)[p retainCount], (int)NSExtraRefCount(p));
[p retain];
NSLog(@"%d (%d)", (int)[p retainCount], (int)NSExtraRefCount(p));
NSIncrementExtraRefCount(p);
NSLog(@"%d (%d)", (int)[p retainCount], (int)NSExtraRefCount(p));
return 0;
}
# On Cocoa:
$ clang proxy.m -framework Foundation&& ./a.out
2011-06-30 14:52:45.314 a.out[63606:903] 0x10010ce90
2011-06-30 14:52:45.318 a.out[63606:903] 1 (0)
2011-06-30 14:52:45.318 a.out[63606:903] 2 (1)
2011-06-30 14:52:45.319 a.out[63606:903] 3 (2)
# On GNUstep:
$ clang `gnustep-config --objc-flags` `gnustep-config --base-libs` proxy.m &&
./a.out
2011-06-30 13:53:55.789 a.out[61681] 0x29ec7c28
2011-06-30 13:53:55.792 a.out[61681] 1 (0)
2011-06-30 13:53:55.795 a.out[61681] 2 (0)
2011-06-30 13:53:55.795 a.out[61681] 2 (1)
- NSProxy retain / release,
David Chisnall <=