retain

performSelector:withObject: and its retain behavior

三世轮回 提交于 2019-11-30 09:11:55
This is an already answer question within SO but I cannot find it in the Apple documentation anywhere . Could you point me in the right direction? Within the following topics Do I have to retain an object before passing it to -performSelector:withObject:afterDelay:? the effect on retain count of performSelector:withObject:afterDelay:inModes Is object that calls performSelector:withObject:afterDelay get retained by the NSRunLoop? the default behaviour seems to be the following: it retains the receiver and the argument(s) . I'm using the following code [[self delegate] performSelector:@selector

Difference between retain and copy?

我是研究僧i 提交于 2019-11-29 22:04:35
问题 What exactly is the difference between retain and copy? what is its significance on reference counting? I know that when an object is allocated using alloc/retain, reference count goes up by one. so how about using copy? Another question relating to this is, the difference between using @property(nonatomic, retain) and @property(nonatomic,copy)? 回答1: retain -- is done on the created object, it just increase the reference count. copy -- create a new object 回答2: Answering your question to the

TableView with SearchController - DEINIT not called

蹲街弑〆低调 提交于 2019-11-29 20:41:16
问题 I have added a search bar and search display controller from the interface builder to my app. I am not able to get it to deinit (dealloc) properly. It is showing the following behavior (swift2, ios9): User doesn't search anything, just selects an item from tableView, DEINIT is called User searches something (or just taps in the search bar), cancel the search, select item from tableView, DEINIT is called User searches something (or just taps the search bar), and selects an item from tableView,

Is there a way to “find mystery retains” …?

故事扮演 提交于 2019-11-29 18:57:31
Recently I was repairing someone's code. There was a big class that would not dealloc. You'd have to hit it with 5 or 6 releases to get it to dealloc. I carefully looked through the big class and eventually found the various things that needed to be released. This got me thinking: there just has to be some really easy way to "find" all the retains on an object .. am I right? So, is there a simple way to "find all the retains" on an object? Is there a button in XCode or Instruments that everyone else knows about? What do you do when you can't find a mystery retain like that? So in the iOS

performSelector:withObject: and its retain behavior

核能气质少年 提交于 2019-11-29 13:45:03
问题 This is an already answer question within SO but I cannot find it in the Apple documentation anywhere . Could you point me in the right direction? Within the following topics Do I have to retain an object before passing it to -performSelector:withObject:afterDelay:? the effect on retain count of performSelector:withObject:afterDelay:inModes Is object that calls performSelector:withObject:afterDelay get retained by the NSRunLoop? the default behaviour seems to be the following: it retains the

Objective-C: ARC forbids explicit message send of 'retain'

天涯浪子 提交于 2019-11-29 09:50:39
I'm new to Objective-C, I try to port an old Objective-C project written in an older version of Objective-C to the new one, but I'm getting the following compiler error: ARC forbids explicit message send of 'retain' in color = [aColor retain]; or color = [[NSColor blackColor] retain]; I was reading about the new automatic reference counting that clang is using now. I have also tried to use Xcode's refactor function but with no luck... What is the proper Objective-C code that need to replace this old code? Simply: color = [NSColor blackColor]; ARC will manage the lifetime of your objects so you

Objective-C retain counts clarification

微笑、不失礼 提交于 2019-11-29 02:46:01
I kind of understand what's retain counts for. But not totally. I looked on google a lot to try to understand but still I don't. And now I'm in a bit of code (I'm doing iPhone development) that I think I should use them but don't know totally how. Could someone give me a quick and good example of how and why using them? Thanks! dmkash The best explanation I ever heard was from Aaron Hillegass: Think of the object as a dog. You need a leash for a dog to keep it from running away and disappearing, right? Now, think of a retain as a leash. Every time you call retain , you add a leash to the dog's

What is the difference between “copy” and “retain”?

有些话、适合烂在心里 提交于 2019-11-28 17:14:20
What is the difference between copy and retain for NSString ? - (void)setString:(NSString*)newString { string = [newString copy]; } Malaxeur In a general setting, retaining an object will increase its retain count by one. This will help keep the object in memory and prevent it from being blown away. What this means is that if you only hold a retained version of it, you share that copy with whomever passed it to you. Copying an object, however you do it, should create another object with duplicate values. Think of this as a clone. You do NOT share the clone with whomever passed it to you. When

Is there a way to “find mystery retains” …?

半腔热情 提交于 2019-11-28 14:09:05
问题 Recently I was repairing someone's code. There was a big class that would not dealloc. You'd have to hit it with 5 or 6 releases to get it to dealloc. I carefully looked through the big class and eventually found the various things that needed to be released. This got me thinking: there just has to be some really easy way to "find" all the retains on an object .. am I right? So, is there a simple way to "find all the retains" on an object? Is there a button in XCode or Instruments that

Question about NSTimer and retain

限于喜欢 提交于 2019-11-28 12:40:02
问题 This code works well @property (nonatomic, retain) NSTimer *timer; self.timer = [[NSTimer timerWithTimeInterval:kAdsAppearTimeInterval target:self selector:@selector(timerFired:) userInfo:nil repeats:NO] retain]; this code get CFRelease . But why? i use retain property self.timer = [NSTimer timerWithTimeInterval:kAdsAppearTimeInterval target:self selector:@selector(timerFired:) userInfo:nil repeats:NO]; 回答1: Not a lot to go on... but: @property (nonatomic, retain) NSTimer *timer; self.timer =