automatic-ref-counting

ARC: How to release static variable?

淺唱寂寞╮ 提交于 2019-12-04 03:07:31
Will dealloc (below) release the NSString pointed to by the static variable exampleString ? // ExampleClass.h @interface ExampleClass : NSObject @end // ExampleClass.m static NSString *exampleString; @implementation ExampleClass - (void)dealloc { exampleString = nil; } - (id)init { self = [super init]; if (self) { exampleString = [NSString stringWithFormat:@"example %@", @"format"]; } return self; } @end Yes, because since you did not specify an ownership qualifier, the LLVM compiler infers that exampleString has __strong ownership qualification. This means that by setting exampleString to nil

Crash in objc_retain in method performed with performSelector

自闭症网瘾萝莉.ら 提交于 2019-12-04 02:58:59
I have this strange crash relating to ARC auto-inserting objc_retains in my code. I have the following two classes: @interface MenuItem : NSObject @property (weak, nonatomic) id target; @property (unsafe_unretained, nonatomic) SEL action; @property (strong, nonatomic) id object; - (instancetype)initWIthTarget:(id)target action:(SEL)action withObject:(id)object; - (void)performAction; @end @implementation MenuItem - (void)performAction { if (self.target && self.action) { if (self.object) { [self.target performSelector:self.action withObject:self.object]; } else { [self.target performSelector

Use Automatic Referencing Count in specific classes in ios

拟墨画扇 提交于 2019-12-04 02:38:56
问题 Actually i came to this question when i was trying to add some classes that have been made upon ios prior to IOS 5 and these classes doesn't having ARC and the project i am trying to add is made upon the IOS 5 and it give me the compile time error related to ARC the classes having suck kind of information that if i try to remove the release/retain then it start behaving irregular.That is my problem, Now come to question i want to know that is there any way so that i can mark those classes not

GData static library: exclude files from ARC with -fno-objc-arc?

有些话、适合烂在心里 提交于 2019-12-04 02:15:21
问题 I am using the GData static library in my app that uses ARC. Google's instructions say to link the header files from the library to the project target. The problem is that when I do so I get compiler errors as the GData library is not compatible with ARC. Google states that: ARC Compatibility When the library source files are compiled directly into a project that uses ARC, then ARC must be disabled specifically for the library sources. To disable ARC for source files in Xcode 4, select the

When is NS_RETURNS_RETAINED needed?

假装没事ソ 提交于 2019-12-04 01:49:07
Take the below example: - (NSString *)pcen NS_RETURNS_RETAINED { return (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (__bridge CFStringRef) self, NULL, (CFStringRef) @"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8); } Is it correct to put the NS_RETURNS_RETAINED there? Another example: + (UIImage *)resizeImage:(UIImage *)img toSize:(CGSize)size NS_RETURNS_RETAINED { UIGraphicsBeginImageContextWithOptions(size, NO, 0.0); [img drawInRect:...]; UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return resizedImage; } That

How can one turn ARC off for specific file

余生长醉 提交于 2019-12-04 00:47:11
I know I am supposed to add the compiler flag -fno-objc-arc to the compile sources in XCode 4 to accomplish this. But it isn't working. Even with the added flag I am still getting errors in my KeychainItemWrapper.m file claiming I need to use __bridge for C pointers. My project is ARC safe, but the Apple provided reference for interacting with the Keychain is not. I would like to just disable ARC for that single file. What else am I missing here? I've had this happen more than once for me in 4.2 in different projects, but then I've not been able to reproduce it reliably enough for a bug report

MKMapView still sending messages to delegate after it's superview has been de-alloc'ed

让人想犯罪 __ 提交于 2019-12-04 00:04:09
EDIT: changed the title. I didn't know it at the time but this is a duplicate of Why am I crashing after MKMapView is freed if I'm no longer using it? This question is similar to Why is object not dealloc'ed when using ARC + NSZombieEnabled but different enough that I thought it worth throwing out there in case anyone understands and can explain to me what is happening. The other question may be an XCode bug so I presume this could be similar. Scenario: RootViewController has a tableView displaying a bunch of items Selecting a cell presents a modal detailViewController containing another

ARC equivalent of autorelease?

痴心易碎 提交于 2019-12-03 23:31:53
If I have this code, + (MyCustomClass*) myCustomClass { return [[[MyCustomClass alloc] init] autorelease]; } This code guarantees the returning object is autoreleased. What's the equivalent of this in ARC? There is no equivalent in ARC, as you don't need to do it yourself. it will happen behind the scenes and you are not allowed to do it your self. You simply use - + (MyCustomClass*) myCustomClass { return [[MyCustomClass alloc] init]; } I suggest you to watch the ARC introduction in the 2011 WWDC as it very simple when you get it. Look here: https://developer.apple.com/videos/wwdc/2011/ And

Disable ARC with Xcode 5

佐手、 提交于 2019-12-03 22:02:42
问题 In versions of Xcode previous to 5, we can disable ARC in the project settings when we create the project. Now ARC is causing this problem for me. With an property list file, for the reading step, the compiler gives me an error: "implicit conversion of 'int' to 'id' is disallowed with ARC". I did not have this problem with the same code with Xcode 4. In my property list file, The keys are numbers and also in my viewController.m When I disallow ARC for the target, the warning persists. I don't

SecItemCopyMatching still leak on osx under ARC

点点圈 提交于 2019-12-03 21:47:51
i found memory leak on SecItemCopyMatching. After investigate on SF i was found solution: __block NSString *certificateName = nil; SecKeychainRef keychain; SecKeychainCopyDefault(&keychain); NSMutableDictionary *attributeQuery = [NSMutableDictionary dictionary]; [attributeQuery setObject: (id) kSecClassIdentity forKey:(__bridge_transfer id) kSecClass]; [attributeQuery setObject: (id) kCFBooleanTrue forKey:(__bridge_transfer id) kSecReturnRef]; [attributeQuery setObject: (id) kSecMatchLimitAll forKey:(__bridge_transfer id) kSecMatchLimit]; CFTypeRef attrResult = NULL; OSStatus status =