automatic-ref-counting

When does a weak reference get updated to nil in Objective-C? [duplicate]

浪尽此生 提交于 2019-11-30 17:45:50
问题 This question already has answers here : Why isn’t my weak reference cleared right after the strong ones are gone? (4 answers) Closed 6 years ago . Consider the following two cases: // case 1 NSObject *strongOne = [[NSObject alloc] init]; NSObject * __weak weakOne = strongOne; if (weakOne) { NSLog(@"weakOne is not nil."); } else { NSLog(@"weakOne is nil."); } strongOne = nil; if (weakOne) { NSLog(@"weakOne is not nil."); } else { NSLog(@"weakOne is nil."); } Outputs this: weakOne is not nil.

App Crashes saying Memory Warning Using Arc [closed]

▼魔方 西西 提交于 2019-11-30 17:43:44
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I am using ARC and the app crashes saying received memory warning . I have used the apple instruments: It looks like I do not have any leaks but I cannot find where is wrong. The crash has to do with the memory and due arc I cannot use release and any sort. It is my first time dealing with memory usage using arc

ARC: “Pointer to non-const type 'id' with no explicit ownership”

徘徊边缘 提交于 2019-11-30 17:35:38
i am upgrading an iOS 4 project to use it with ARC with the sdk5. So i want to use the automatic refactor method for converting the code to use ARC. Unfortunately it does´t work. I get a lots of errors.. for(id* child in childObjectArray){ [child removeParentGroupReferences]; } That gives me the following error output: Pointer to non-const type 'id' with no explicit ownership Any help about that? What do i have to change? Thanks for any help.. Change id* to id . id is already defined as an object pointer. id is a type, not an object. That means that id shouldn't be a pointer. Remove the * to

Why does NSObject's “isMemberOfClass:class” specify __unsafe_unretained in XCode's autocompletion?

我只是一个虾纸丫 提交于 2019-11-30 17:18:45
问题 The vague overview is that I'm writing a method in an NSArray Category that will take a Class and filter an Array down to elements that are members of that class. Something like: @implementation NSArray(filter) -(NSArray*)objectsOfClass:(Class)aClass { NSMutableArray *ret = [[NSMutableArray alloc] init]; for (id obj in self) if ([obj isMemberOfClass:aClass]) [ret addObject:obj]; return [NSArray arrayWithArray:ret]; } @end Sooo, with that out of the way, on to my question. NSObject.h shows

What is the correct way of init iVar variables in presence of ARC

我怕爱的太早我们不能终老 提交于 2019-11-30 16:32:08
Example iVar foo , @property (nonatomic) NSString* foo; // inside .h Option 1 @Synthesize foo; //Inside .m foo = [[NSString alloc] init]; // viewDidLoad method Option 2 @Synthesize foo; //Inside .m self.foo = [[NSString alloc] init]; // viewDidLoad method Option 3 @Synthesize foo = _foo; //Inside .m _foo = [[NSString alloc] init]; // viewDidLoad method Why? At so many places I have seen code which has different ways of doing init an Object in Obj - C but which one is the best practise? justin In this regard, ARC is the same as MRC. you have specified all these take place in viewDidLoad . in

Understanding task_basic_info task resident_size

别等时光非礼了梦想. 提交于 2019-11-30 16:03:58
short question: someone (cit. 5 ) told me that resident memory could be reclaimed by my system. What does this mean? Does it mean that my App is not using that memory or is the resident memory value directly related to the memory being currently used by my App? I haven't found much documentation on this apart from those answers . I am trying to solve an issue. I am writing a game usign iOS 6.0 and Cocos2d 2.0 and I do get some memory problems. I have Cococs2d 2.0 as static library and I wrote my code using ARC (which I suspect being the reason). Going from Initial scene to Character Selection

UIViewController -dealloc method not called

天涯浪子 提交于 2019-11-30 15:48:44
问题 I am working with Automatic Reference Counting. I have a custom UIViewController subclass and whenever I call -presentViewController: animated:completion: or remove its view from the superview I would like to NSLog something like "I am dealloced" so I know that the view controller has successfully been removed. I have implemented the -dealloc method in my view controller. However I started a test project where I just had two UIViewController instances (no retain cycles) and -dealloc is not

Understand one edge case of block memory management in objc

孤街醉人 提交于 2019-11-30 15:48:35
the code below will crash because of EXC_BAD_ACCESS typedef void(^myBlock)(void); - (void)viewDidLoad { [super viewDidLoad]; NSArray *tmp = [self getBlockArray]; myBlock block = tmp[0]; block(); } - (id)getBlockArray { int val = 10; //crash version return [[NSArray alloc] initWithObjects: ^{NSLog(@"blk0:%d", val);}, ^{NSLog(@"blk1:%d", val);}, nil]; //won't crash version // return @[^{NSLog(@"block0: %d", val);}, ^{NSLog(@"block1: %d", val);}]; } the code runs in iOS 9 with ARC enabled. And I was trying to figure out the reason that lead to crash. by po tmp in lldb I found (lldb) po tmp <_

UIViewController -dealloc method not called

流过昼夜 提交于 2019-11-30 14:43:06
I am working with Automatic Reference Counting. I have a custom UIViewController subclass and whenever I call -presentViewController: animated:completion: or remove its view from the superview I would like to NSLog something like "I am dealloced" so I know that the view controller has successfully been removed. I have implemented the -dealloc method in my view controller. However I started a test project where I just had two UIViewController instances (no retain cycles) and -dealloc is not called either when I push the second UIViewController modally or when I remove the superview or when I

How to activate Cycles reporting in Instruments under ARC?

孤人 提交于 2019-11-30 13:58:26
问题 Instruments can visualize retain cycles under ARC in a graphically interesting way. I also remember that a few days ago I spotted the "Cycles" view in Instruments by accident. Now where I started using ARC, suddenly I'm not able to find that anymore. The Allocations and VM Tracker instruments don't offer it, and the Leaks instrument either. What must I do in order to see retain cycles? Found a screenshot as evidence: 回答1: Using Xcode 4.2.1, I found the it in "Leaks", under "Cycles & Roots".