autorelease

Autorelease iPhone

南笙酒味 提交于 2019-12-03 06:26:30
问题 Coming up towards the end of developing an iPhone application and I'm wondering just how bad is it to use autorelease when developing for the iphone. I'm faced with some fairly random crashes and, so far, I can't pinpoint it to anything other than sloppy memory usage. As a Cocoa newbie I remember initially reading a guideline document that strongly suggested avoiding autorelease in favor of manual retain/release for iPhone. However, a more 'senior' Cocoa developer came on board early on (who

iOS autorelease pool blocks

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 21:49:23
I was reading the documentation from apple about memory management when I got to autorelease pool blocks and something got me thinking. Any object sent an autorelease message inside the autorelease pool block is released at the end of the block. I am not sure I fully understand this. Any object created inside an autorelease pool block gets released at the end of the block anyway because that is it's life span. Why would you need to call autorelease to the object when it is going to get released anyway when it reaches the end of the block? To be clearer, I will give an example, of what I am

Autorelease iPhone

两盒软妹~` 提交于 2019-12-02 20:59:49
Coming up towards the end of developing an iPhone application and I'm wondering just how bad is it to use autorelease when developing for the iphone. I'm faced with some fairly random crashes and, so far, I can't pinpoint it to anything other than sloppy memory usage. As a Cocoa newbie I remember initially reading a guideline document that strongly suggested avoiding autorelease in favor of manual retain/release for iPhone. However, a more 'senior' Cocoa developer came on board early on (who ironically has been let go since), who used autorelease all over the place. Admittedly, I was went into

Objective-C autorelease pool not releasing object

只愿长相守 提交于 2019-12-01 21:54:52
I am very new to Objective-C and was reading through memory management. I was trying to play around a bit with the NSAutoreleasePool but somehow it wont release my object. I have a class with a setter and getter which basically sets a NSString *name. After releasing the pool I tried to NSLog the object and it still works but I guess it should not? @interface TestClass : NSObject { NSString *name; } - (void) setName: (NSString *) string; - (NSString *) name; @end @implementation TestClass - (void) setName: (NSString *) string { name = string; } - (NSString *) name { return name; } @end int main

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

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

Releasing objects returned by method

冷暖自知 提交于 2019-11-30 22:23:03
Ok, I know the answer to this question should be obvious, but I need a little push in the right direction. I find myself writing a fair number of methods that follow the following pattern: -(NSThing*)myMethod{ NSThing *thing = [[NSthing alloc] init]; // do some stuff with the thing return thing; } My question is, how do I handle the release of this object? Clearly I can't release it within the method. usually you would autorelease it -(NSThing*)myMethod{ NSThing *thing = [[NSthing alloc] init]; // do some stuff with the thing return [thing autorelease]; } Autoreleasing is the easy way to get

Releasing objects returned by method

情到浓时终转凉″ 提交于 2019-11-30 18:14:56
问题 Ok, I know the answer to this question should be obvious, but I need a little push in the right direction. I find myself writing a fair number of methods that follow the following pattern: -(NSThing*)myMethod{ NSThing *thing = [[NSthing alloc] init]; // do some stuff with the thing return thing; } My question is, how do I handle the release of this object? Clearly I can't release it within the method. 回答1: usually you would autorelease it -(NSThing*)myMethod{ NSThing *thing = [[NSthing alloc]

When is an autoreleased object actually released?

青春壹個敷衍的年華 提交于 2019-11-30 17:24:50
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 { NSString *stringA; stringA = [[[NSString alloc] initWithString:@"Hello"] autorelease] return stringA; }

Why is there no autorelease pool when I do performSelectorInBackground:?

只愿长相守 提交于 2019-11-30 07:33:22
I am calling a method that goes in a background thread: [self performSelectorInBackground:@selector(loadViewControllerWithIndex:) withObject:[NSNumber numberWithInt:viewControllerIndex]]; then, I have this method implementation that gets called by the selector: - (void) loadViewControllerWithIndex:(NSNumber *)indexNumberObj { NSAutoreleasePool *arPool = [[NSAutoreleasePool alloc] init]; NSInteger vcIndex = [indexNumberObj intValue]; Class c; UIViewController *controller = [viewControllers objectAtIndex:vcIndex]; switch (vcIndex) { case 0: c = [MyFirstViewController class]; break; case 1: c =