automatic-ref-counting

Block recursion and breaking retain cycle

别说谁变了你拦得住时间么 提交于 2019-12-04 16:15:42
问题 To better illustrate the question, consider the following simplified form of block recursion: __block void (^next)(int) = ^(int index) { if (index == 3) { return; } int i = index; next(++i); }; next(0); XCode (ARC-enabled) warns that " Capturing 'next' strongly in this block is likely to lead to a retain cycle ". Agreed. Question 1 : Would the retain cycle be successfully broken by setting the block itself to nil , in this fashion: __block void (^next)(int) = ^(int index) { if (index == 3) {

Cannot use respondsToSelector using ARC on Mac

扶醉桌前 提交于 2019-12-04 14:54:38
问题 When I call respondsToSelector in an ARC environment, I get the following error message Automatic Reference Counting Issue No known instance method for selector respondsToSelector: This is the header #import <AppKit/AppKit.h> @class MTScrollView; @protocol MTScrollViewDelegate -(void)scrollViewDidScroll:(MTScrollView *)scrollView; @end @interface MTScrollView : NSScrollView { } @property(nonatomic, weak) id<MTScrollViewDelegate>delegate; @end This is the implementation file #import

How to keep a variable in memory until the app quits

扶醉桌前 提交于 2019-12-04 14:37:11
I have a singleton object in iOS that when instantiated parses a CSV file and then holds the results. I would like to make this object universally accessible and I would like it to not be released from memory until the app quits. I am running ARC so I cannot do manual retains. Is there a way I can do this so it will work with ARC? Header File: #import <Foundation/Foundation.h> #import "CHCSV.h" #import "RCParserObject.h" @interface ParserStore : NSObject <CHCSVParserDelegate> { // CSV Variables RCParserObject *item; NSMutableArray *data; NSMutableArray *parsedData; int fields; bool open; }

When do these objects get released under ARC?

我是研究僧i 提交于 2019-12-04 14:17:05
I have a few questions about ARC (automatic reference counting): CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:appPath]; //Question 1: Here, I would expect the NSURL object to be autoreleased and //therefore the CFURLRef will also be available for “a while.” Is this correct? url = NULL; //Question 2: Will this cause the NSURL to be released immediately? NSURL *url = [NSURL fileURLWithPath:appPath]; url = nil; //Question 3: Does the “url = nil” result in an immediate release of the NSURL? NSURL *url = [[NSURL alloc] initWithString:@"/something"]; url = nil; //Question 4: What about

Subclass non-ARC file into ARC project in Xcode 4

痴心易碎 提交于 2019-12-04 13:47:47
问题 I am using some non-ARC code in my ARC project, namely Three20. I have added all the appropriate compiler flags and all works well. However, I need to subclass some of the Three20 classes, and I'm not sure if I should add the compiler flag to my new file for non-ARC, or if the compiler will figure it out, and add the appropriate release calls. Just to recap: - ARC project in XCode 4 - Includes non-ARC code (Three20) - Need to subclass something defined in non-ARC files - Do I need to add

Converting object_setInstanceVariable() to ARC?

£可爱£侵袭症+ 提交于 2019-12-04 13:40:44
I wish to convert an instance of object_setInstanceVariable(self, [key UTF8String], *(id**)addr); to ARC. When I try to use Xcode built-in Objective-C ARC converter I get the following error: 'object_setInstanceVariable' is unavailable: not available in automatic reference counting mode How should I handle this problem? I know I can put --fno-objc-arc as Compiler flag, but I would very much like to use ARC instead, if it's possible (I have a lot of targets that I otherwise would have to manually change the Compiler flag for). (The code is originally taken from NSObject+NSCoding and Archiver by

Out parameters in ARC Objective C

心不动则不痛 提交于 2019-12-04 13:02:30
I'm new to objective C, and I don't know how to create and call a method with out parameters when compiling the code with the new ARC compiler. This is the kind of thing I'm trying to accomplish in non-ARC objective C (this is probably wrong anyway). // // Dummy.m // OutParamTest #import "Dummy.h" @implementation Dummy - (void) foo { NSString* a = nil; [self barOutString:&a]; NSLog(@"%@", a); } - (void) barOutString:(NSString * __autoreleasing *)myString { NSString* foo = [[NSString alloc] initWithString:@"hello"]; *myString = foo; } @end (Edited to match suggestion). I've read the

What does objc_autoreleaseReturnValue mean?

我的梦境 提交于 2019-12-04 12:53:07
I have a method createATestObject . As its name indicates, it create an object and return it. The code is very simple and it is under ARC. - (TestObj *)createATestObj { return [[TestObj alloc] init] ; } I assembly the file and get the assembly code below. Lfunc_begin4: .cfi_startproc @ BB#0: push {r7, lr} mov r7, sp sub sp, #8 @DEBUG_VALUE: -[ViewController createATestObj]:self <- undef @DEBUG_VALUE: -[ViewController createATestObj]:_cmd <- undef str r0, [sp, #4] str r1, [sp] movw r0, :lower16:(L_OBJC_CLASSLIST_REFERENCES_$_-(LPC4_0+4)) movt r0, :upper16:(L_OBJC_CLASSLIST_REFERENCES_$_-(LPC4_0

Make CVDisplayLink + Automatic Reference Counting play well together

你说的曾经没有我的故事 提交于 2019-12-04 12:14:35
I recently switched from using NSTimer to CVDisplayLink to redraw my OpenGL animation, but i've got a little problem making it work with ARC switched on: /* * This is the renderer output callback function. */ static CVReturn displayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp* now, const CVTimeStamp* outputTime, CVOptionFlags flagsIn, CVOptionFlags* flagsOut, void* displayLinkContext) { // now is the time to render the scene [((__bridge BDOpenGLView*)displayLinkContext) setNeedsDisplay:YES]; // always succeeds, because we don't actually do anything here anyway return

@autoreleasepool semantics

假装没事ソ 提交于 2019-12-04 11:28:23
问题 I was reading the ARC docs on the llvm site: http://clang.llvm.org/docs/AutomaticReferenceCounting.html#autoreleasepool ..in particular about @autoreleasepool. In lot of current implementation using NSAutoreleasePool, I see cases where the pool is drained periodically during a loop iteration - how do we do the same with @autorelease pool, or is it all done for us somehow under the hood? Secondly, the docs state that if an exception is thrown, the pool isn't drained.... ok exceptions are by