autorelease

ARC equivalent of autorelease?

风流意气都作罢 提交于 2020-01-12 13:34:49
问题 If I have this code, + (MyCustomClass*) myCustomClass { return [[[MyCustomClass alloc] init] autorelease]; } This code guarantees the returning object is autoreleased. What's the equivalent of this in ARC? 回答1: There is no equivalent in ARC, as you don't need to do it yourself. it will happen behind the scenes and you are not allowed to do it your self. You simply use - + (MyCustomClass*) myCustomClass { return [[MyCustomClass alloc] init]; } I suggest you to watch the ARC introduction in the

Autorelease pools in Objective-C - release main AutoreleasePool?

↘锁芯ラ 提交于 2020-01-12 07:35:09
问题 By my understanding, when an object is sent an autorelease message, if no autorelease pools exist other than the one in main.m , the object gets placed in the one in main.m . Assuming this is correct, I have a couple of questions: 1) Do all autoreleased objects stay in that pool until the termination of the app? 2) If 1 is true, does creating an autoreleased object without a local autorelease pool (therefore placing that object in the main.m pool) keep that object in memory until termination

Obj-c autorelease a variable up a chain of methods

纵然是瞬间 提交于 2020-01-06 07:27:11
问题 I'm new to Obj-C and I have a question concerning the autorelease. Is it ok to return an autoreleased variable for several methods? For example: - (void) methodC { Object anObj = [self methodB]; //Do something with anObj } - (Object *) methodB { return [self methodA]; } - (Object *) methodA { Object anObj = [[anObj alloc] init]; release [anObj autorelease]; } Will the variable remain valid even if it is returned up a method chain and used at the top? Or does it have to be retained somewhere

Best way to periodically drain the autorelease pool on a long-running background thread?

此生再无相见时 提交于 2020-01-03 12:17:30
问题 In the developer documentation, it says: If your application or thread is long-lived and potentially generates a lot of autoreleased objects, you should periodically drain and create autorelease pools (like the Application Kit does on the main thread); otherwise, autoreleased objects accumulate and your memory footprint grows. If, however, your detached thread does not make Cocoa calls, you do not need to create an autorelease pool. I was wondering what the best way to do this is. I have

Leak or Crash - difference between autorelease and release

核能气质少年 提交于 2020-01-02 11:27:13
问题 I have a comprehension question. This method is given: - (NSArray*)test { NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://stackoverflow.com/"]]; NSString *result = [[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSMacOSRomanStringEncoding]; result = [result stringByAppendingString:@"something"]; NSArray *arr = [NSArray arrayWithObject:result]; //[result release]; return arr; } If I uncomment the release the App would crash and say it

[myArray addObject:[[objcBlock copy] autorelease]] crashes on dealloc'ing the array

ぃ、小莉子 提交于 2020-01-01 11:58:07
问题 I wrote a class for declaratively describing a sequence of UIView animations. My method takes a vararg of animation blocks and puts them in an array. So in my loop I want to do this: [animations addObject:[[block copy] autorelease]]; I first copy the block so that it is moved to the heap, allowing it to be retain 'ed by the array. Then I autorelease it to relinquish ownership (because the array retains it). However this crashes when the animations array is dealloc'd. (My understanding is that

Problems with memory management, autorelease, permanent heap is sometimes 250+ kb on iOS

﹥>﹥吖頭↗ 提交于 2019-12-31 04:05:12
问题 I'm really pulling my hair out on this one, it seems that I'm having severe issues with memory management on an iOS app. Here's the case: first I load table. When the user taps a cell, it presents a complicated view. The most memory consuming about the view is that it's loading 20+ UIImage s of 500x500. There are two other tabs in that view, loading a list of media (those UIImage s, but then in a table) and another simple table. When I return back to the first table view, apparently over 250

When is an autoreleased object actually released?

ぃ、小莉子 提交于 2019-12-30 05:57:11
问题 I am new in objective-c and I am trying to understand memory management to get it right. After reading the excellent Memory Management Programming Guide for Cocoa by apple my only concern is when actually an autoreleased object is released in an iphone/ipod application. My understanding is at the end of a run loop . But what defines a run loop in the application? So I was wondering whether the following piece of code is right. Assume an object @implementation Test - (NSString *) functionA {

When is an autoreleased object actually released?

耗尽温柔 提交于 2019-12-30 05:56:12
问题 I am new in objective-c and I am trying to understand memory management to get it right. After reading the excellent Memory Management Programming Guide for Cocoa by apple my only concern is when actually an autoreleased object is released in an iphone/ipod application. My understanding is at the end of a run loop . But what defines a run loop in the application? So I was wondering whether the following piece of code is right. Assume an object @implementation Test - (NSString *) functionA {

How to set specific release date in new iTunesConnect interface after approval?

对着背影说爱祢 提交于 2019-12-24 05:10:29
问题 Can anyone tell me how to set a specific release date in new iTunesConnect interface, after approval with pending developer release state? Our release should for some reason at a weekend now, so changing from manually release to a date would be nice. But now where the app is in pending developer release state, I can not find the option for a specific release date anymore. 回答1: According to Apple App distribution guide: Use iTunes Connect to set a date when the app is available on the store.