automatic-ref-counting

Why setting object that is undergoing deallocation to weak property results in crash

匆匆过客 提交于 2019-12-01 15:40:38
In Clang's Objective-C Automatic Reference Counting we see the following For __weak objects, the lvalue is updated to point to the new pointee, unless the new pointee is an object currently undergoing deallocation, in which case the lvalue is updated to a null pointer. This must execute atomically with respect to other assignments to the object, to reads from the object, and to the final release of the new pointee. In objc-weak.mm wee see the following chunk of code in weak_register_no_lock() : if (deallocating) { if (crashIfDeallocating) { _objc_fatal("Cannot form weak reference to instance (

Want to perform action when __weak ivar is niled

走远了吗. 提交于 2019-12-01 15:30:56
问题 I have a @class Foo which contains a __weak id bar ivar. Several actions from methods in different classes can cause the object to disappear and thus get bar niled. I want to perform an action when the ivar is automatically niled by ARC. If possible, I would want to avoid turning bar into a property or using Key-Value Observing. Is this even possible? If not, can KVO be used against non-property ivars? 回答1: I was led here by a duplicate question, here is what I answered: You can't do that

Use Automatic Referencing Count in specific classes in ios

倖福魔咒の 提交于 2019-12-01 14:37:30
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 to use ARC so that the newly created classes that having base SDK ios5 compile with ARC and i mention

Why setting object that is undergoing deallocation to weak property results in crash

自闭症网瘾萝莉.ら 提交于 2019-12-01 13:44:40
问题 In Clang's Objective-C Automatic Reference Counting we see the following For __weak objects, the lvalue is updated to point to the new pointee, unless the new pointee is an object currently undergoing deallocation, in which case the lvalue is updated to a null pointer. This must execute atomically with respect to other assignments to the object, to reads from the object, and to the final release of the new pointee. In objc-weak.mm wee see the following chunk of code in weak_register_no_lock()

Automatic Reference Counting (ARC) says that invoking [super dealloc] is forbidden…what is the alternative?

狂风中的少年 提交于 2019-12-01 13:41:53
问题 I'm starting to use iOS5 and I've enabled ARC for my project. I have a class where on deallocation I save the state of that object. -(void)dealloc { [self save]; [super dealloc]; } However, under ARC, [super dealloc] is not allowed? I thought that it was considered a bug if you don't invoke the dealloc method on the super class in this situation? So what is the appropriate way to dealloc objects now? 回答1: ARC in iOS 5 is under NDA. That said, judging from publicly available information at the

Is AutoRelease redundant when using ARC in Objective-C?

梦想的初衷 提交于 2019-12-01 13:33:51
I'm pretty new to Objective-C, as you may gather, and until recently, I hadn't really understood the need for all this AutoRelease malarky. I think that's mostly because I've started Objective-C with ARC, and haven't had any exposure to doing retains and release. Anyway, my understanding now is that pre-ARC, if you created an object and needed to return a pointer to it as the returning object of the method/function, you would need to autorelease it, because you are unable to do the "[obj release]" after doing "return obj;" Worrying about retains and releases isn't an issue with ARC. Does this

Runtime memory leaked warnings when executing objective-C code within C code with ARC enabled

久未见 提交于 2019-12-01 12:27:51
ARC is enabled and bufferReady is being triggered by a C++ library(non-ARC enabled), and I'm sure I'm missing an ARC cast somewhere. Please advise. Thanks in advance. With the code below: @implementation HelloWorldLayer id refToSelf; //reference to self int shakeCounter = 0; void bufferReady() { if (shakeCounter % 100 == 0) { [refToSelf shakes]; } shakeCounter++; } - (void) shakes { CCRotateBy * rotate = [CCRotateBy actionWithDuration:0.1 angle:2]; CCActionInterval * rotateReverse = [rotate reverse]; CCSequence * seq1 = [CCSequence actions:rotate, rotateReverse, nil]; CCMoveBy * shake =

EXC_BAD_ACCESS when I close my window, which is also my application's delegate

倾然丶 夕夏残阳落幕 提交于 2019-12-01 12:25:49
问题 I wrote a Cocoa Application and I got EXC_BAD_ACCESS error when I'm closing an application window. I read that this error usually means problems with memory, but I have ARC mode on and I don't need care about releasing e.t.c. (xCode forbids me to call this functions and manage memory automatically). Error is pointing at line return NSApplicationMain(argc, (const char **)argv); in main function. Here's my application's code: .h file: @interface MainDreamer : NSWindow <NSWindowDelegate> {

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

十年热恋 提交于 2019-12-01 11:53:05
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 project and the target in Xcode. Under the target "Build Phases" tab, expand the Compile Sources build

Is AutoRelease redundant when using ARC in Objective-C?

六月ゝ 毕业季﹏ 提交于 2019-12-01 11:32:01
问题 I'm pretty new to Objective-C, as you may gather, and until recently, I hadn't really understood the need for all this AutoRelease malarky. I think that's mostly because I've started Objective-C with ARC, and haven't had any exposure to doing retains and release. Anyway, my understanding now is that pre-ARC, if you created an object and needed to return a pointer to it as the returning object of the method/function, you would need to autorelease it, because you are unable to do the "[obj