automatic-ref-counting

Lifetime of weak local variables with ARC

僤鯓⒐⒋嵵緔 提交于 2019-11-29 07:32:11
If I have a piece of code that looks like this: - (void)testSomething { __weak NSString *str = [[NSString alloc] initWithFormat:@"%@", [NSDate date]]; NSLog(@"%@", str); } the output will be (null) because there are no strong references to str and it will be immediately released after I allocate it. This makes sense and is spelled out in the Transitioning to ARC guide. If my code looks like this: - (void)testSomething { __weak NSString *str = [NSString stringWithFormat:@"%@", [NSDate date]]; NSLog(@"%@", str); } then it correctly prints out the current date. Obviously you would expect it to

Convert non-ARC to ARC project without recreate it? [closed]

你说的曾经没有我的故事 提交于 2019-11-29 07:11:44
问题 I'm just wondering if it's possible to convert a non-ARC project to ARC without recreate it at all ? Thank you 回答1: With Xcode 7 you use the Edit | Convert | Convert to Objective-C ARC menu. Pre-Xcode 7: In Xcode, use the Edit | Refactor | Convert to Objective-C ARC menu. No need to recreate the project. 来源: https://stackoverflow.com/questions/13039779/convert-non-arc-to-arc-project-without-recreate-it

ARC: Setting compiler flags to -fno-objc-arc and build errors

不羁的心 提交于 2019-11-29 07:10:43
Following a stackoverflow topic about disabling ARC compiler mechanism for specific classes, I added the -fno-objc-arc argument to Compiler Flags column under Compile Sources section (Buil Phases tab within TARGETS project). Even if settings have been validated, I'm not able to build my application since the compiler says that retain, release, etc. cannot be used under ARC. How can I fix the above problem? Thank you in advance. Did you use the migration tool to perform your migration? Did you add the compiler flags to all the files that has release/retain? I wrote about ARC migration on my

What is the difference Memory Leak and a Zombie?

北城以北 提交于 2019-11-29 06:25:22
问题 I am working on a ARC based project . I have never worked on Non ARC based project .Recently I came across a zombie in my ARC enabled project.As far as I understood there wont be memory leaks in ARC , as the objects will be deallocated automatically.But I came across a zombie saying "message passed to a deallocated instance".My confusion is is a Memory Leak equivalent to a Zombie. If that is the case then Memory Leak occur in ARC too ? Any help ? 回答1: "Zombies" in Objective-C parlance are the

Files doesn't support the ARC feature, how to deal with

孤人 提交于 2019-11-29 04:36:14
My project uses the ARC(Automatic Reference Counter), so when i try to import the ASIHTTPRequest library which has 4 classes that used in their implementation the autorelease statement, here is an example: [self setAccessLock:[[[NSRecursiveLock alloc] init] autorelease]]; The error that i got: ARC forbids explicit message send of autorelease What should i do to solve this problem. I have got the solution, i needed to add the right flags to the compiler flags for each file which doesn't support the ARC. For me, i use Xcode 4.2, so under target -> Build Phases -> Compile Sources , double click

Objective-C ARC Error: -fobjc-arc is not supported with fragile abi

空扰寡人 提交于 2019-11-29 04:29:12
I'm having a problem trying to migrate my iPhone app to the new ARC technology. When I try to convert the code, the following error shows up 29 times: Apple LLVM compiler 3.0 Error -fobjc-arc is not supported with fragile abi What does this mean? And more importantly, how can I fix it? Thanks in advance! From Apple's developer forums This is an unfortunate bug in Seed 3, where the migrator and simulator aren't working well together. To address this, just switch to a device target, then do migration. change compiler. Set the project compiler to "LLVM GCC 4.2", instead of "Apple LLVM 3.0"; ARC

How do I return a struct value from a runtime-defined class method under ARC?

本秂侑毒 提交于 2019-11-29 04:23:24
I have a class method returning a CGSize and I'd like to call it via the Objective-C runtime functions because I'm given the class and method names as string values. I'm compiling with ARC flags in XCode 4.2. Method signature: +(CGSize)contentSize:(NSString *)text; The first thing I tried was to invoke it with objc_msgSend like this: Class clazz = NSClassFromString(@"someClassName); SEL method = NSSelectorFromString(@"contentSize:"); id result = objc_msgSend(clazz, method, text); This crashed with "EXC_BAD_ACCESS" and without a stack trace. I used this first because the documentation for objc

Include non-ARC library in an ARC app?

て烟熏妆下的殇ゞ 提交于 2019-11-29 04:16:18
So, is it possible? I get this error multiple times: ARC forbids Objective-C objects in structs or unions For example here: typedef struct { BOOL _field1; union { struct { id _field1; id _field2; } _field1; GSEventRef _field2; } _field2; } XXStruct_CKAdxD; You need to add -fno-objc-arc to the compiler options for each file that doesn't / can't use ARC. Within Xcode you do this from the 'Compile Sources' build phase of your target. Double click the file and add -fno-objc-arc to the box that pops up. 来源: https://stackoverflow.com/questions/8969634/include-non-arc-library-in-an-arc-app

Does cocos2d support ARC?

柔情痞子 提交于 2019-11-29 03:49:51
I am using Xcode 4.2 and building a game for iphone (from iOS 3.0 - 5.0). Does cocos2d support ARC? What modifications needs to be made to convert code written in previous versions? If I use the strong and weak keywords for variables and set compiler to LLVM GCC 4.2, what will be the results? Is it a necessity to change compiler to 3.0 to support ARC? Cocos2d v1.1 and v2.0 are compatible with ARC. However, the cocos2d code itself does not use ARC and there are no templates provided by cocos2d that you can use to start programming with ARC. You are required to add a seperate static library

Recursive Blocks in Objective-C leaking in ARC

北慕城南 提交于 2019-11-29 03:31:47
So I'm using recursive blocks. I understand that for a block to be recursive it needs to be preceded by the __block keyword, and it must be copied so it can be put on the heap. However, when I do this, it is showing up as a leak in Instruments. Does anybody know why or how I can get around it? Please note in the code below I've got references to a lot of other blocks, but none of them are recursive. __block NSDecimalNumber *(^ProcessElementStack)(LinkedList *, NSString *) = [^NSDecimalNumber *(LinkedList *cformula, NSString *function){ LinkedList *list = [[LinkedList alloc] init]; NSDictionary