automatic-ref-counting

super dealloc on ARC subclasses

帅比萌擦擦* 提交于 2019-12-05 13:12:15
In ARC I'm aware that you do not call [super dealloc] in any overrides of -dealloc , so typically I remove observers and timers in there without doing so. However, if I were to subclass a view that I made that releases observation info in -dealloc without calling [super dealloc] in the subclass' implementation of the method, would the super implementation be called automatically to release the observation info handled by the superclass, or would it leak? herzbube The superclass' implementation of dealloc is automatically called (as far as I know, the compiler inserts the statement [super

No known instance method for selector

穿精又带淫゛_ 提交于 2019-12-05 12:17:57
I'm developing an iOS 4 application using latest SDK, XCode 4.2 and ARC . I've added a method to appDelegate.h #import <UIKit/UIKit.h> @class ViewController; @class SecondViewController; @interface AppDelegate : UIResponder <UIApplicationDelegate> { UINavigationController* navController; ViewController* viewController; SecondViewController* secondViewController; } @property (strong, nonatomic) UIWindow *window; - (void) showSecondViewController; @end And it's implemented in appDelegate.m #import "AppDelegate.h" #import "ViewController.h" #import "SecondViewController.h" @implementation

ARC circular reference in objective-c uses delegate

感情迁移 提交于 2019-12-05 11:15:41
Hello! I tried to use a delegate in my app. My project uses ARC For example, I have protocol X and two object which uses it. In object B I created an instance for object A and set delegate self (A.delegate = self) In runtime I invoke a method callBack (in this point my delegate object is B ). After that they all execute the -showResult method. At what point is a circular reference formed? I understand that this is a problem with the specifier strong , but I don't understand what time it happened, and how to track it. Thanks! If two objects both maintain strong references to each other (that is

“Missing [super dealloc]” warning in an ARC project

戏子无情 提交于 2019-12-05 09:18:09
I've refactored a project to ARC. It looks fine, but there is an object which uses the notification center. I removed the observer in a custom dealloc method. That worked fine in the non ARC project. It also works in ARC, but I get a crazy warning: "Method possibly missing a [super dealloc] call." In an ARC project it is automatically done for me, when the method ends. Even better: I must not call it in ARC projects! This must be an XCode bug, right? Here's my code: - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; // [super dealloc]; will be called automatically }

ARC & Malloc: EXEC_BAD_ACCESS

丶灬走出姿态 提交于 2019-12-05 08:48:27
I have been working on a project for some time now, and I decided to make the jump to ARC. I came across some code that was bombing out every time, and I would like to know why. I have managed to simplify it down to this snippet: typedef __strong id MYID; int main(int argc, char *argv[]) { MYID *arr = (MYID *) malloc(sizeof(MYID) * 4); arr[0] = @"A"; // always get an EXEC_BAD ACCESS HERE arr[1] = @"Test"; arr[2] = @"Array"; arr[3] = @"For"; // uh oh, we need more memory MYID *tmpArray = (MYID *) realloc(arr, sizeof(MYID) * 8); assert(tmpArray != NULL); arr = tmpArray; arr[4] = @"StackOverflow"

How do I recover from EXC_BAD_ACCESS?

二次信任 提交于 2019-12-05 08:20:51
I'm intentionally causing an EXC_BAD_ACCESS . By triggering a write to an NSObject in a read-only virtual memory page. Ideally, I'd like to catch EXC_BAD_ACCESS , mark the virtual memory page as read-write and have execution continue as it normally would have. Is this even possible? The code I've written to cause the EXC_BAD_ACCESS is below. WeakTargetObject.h (ARC) @interface WeakTargetObject : NSObject @property (nonatomic, weak) NSObject *target; @end WeakTargetObject.m (ARC) @implementation WeakTargetObject @end main.m (MRR) - (void)main { char *mem = NULL; vm_allocate(mach_task_self(),

Dismissing Popover, [UIPopoverController dealloc] reached while popover is still visible

坚强是说给别人听的谎言 提交于 2019-12-05 08:14:30
I have a UIPopoverController stored in a strong property in my View Controller. When the user rotates the iPad while the popover is visible, I dismiss the popover and set my property to nil. if (self.popover != nil) { [self.popover dismissPopoverAnimated:NO]; self.popover.delegate = nil; self.popover = nil; } When the code gets to self.popover = nil, ARC attempts to dealloc the UIPopoverController, but it crashes because it is supposedly still visible. How am I supposed to dismiss and nil out the popover without it crashing? First off, it would be advisable to check if the popover is being

Why does ARC autorelease when using weak references?

走远了吗. 提交于 2019-12-05 07:43:40
Why can't ARC use a regular release? Example: [weakObject doSomething]; From what I understand, ARC turns this into: Object *strongObject = objc_autorelease(objc_loadWeakRetained(weakObject)); [strongObject doSomething]; Why doesn't ARC do this instead?: Object *strongObject = objc_loadWeakRetained(weakObject); [strongObject doSomething]; objc_release(strongObject); I'd like to do away with as many autoreleases in ARC as possible. I do a lot of async threading with GCD and I end up having to add autorelease pools a lot: dispatch_async(self.myQueue, ^{ @autoreleasepool{ [weakObject

Objective-C: blocks in ARC

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 07:03:41
I'm transitioning to ARC (Automatic Reference Counting) and this document was very helpful: Transitioning to ARC Release Notes . It says: How do blocks work in ARC? Blocks “just work” when you pass blocks up the stack in ARC mode, such as in a return. You don’t have to call Block Copy any more. You still need to use [^{} copy] when passing “down” the stack into arrayWithObjects: and other methods that do a retain. Can somebody elaborate on this a little bit or give some example? I understood that to mean usually I don't need to do [block copy] anymore even if the block is used outside the

SecItemCopyMatching still leak on osx under ARC

寵の児 提交于 2019-12-05 06:53:42
问题 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