nsautoreleasepool

does NSThread create autoreleasepool automatically now?

ⅰ亾dé卋堺 提交于 2019-11-28 08:43:04
I have test code like this - (void)viewDidLoad { [super viewDidLoad]; NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(test) object:nil]; [thread start]; } -(void)test { MyClass *my = [[[MyClass alloc] init] autorelease]; NSLog(@"%@",[my description]); } I did not create any autoreleasepool for my own thread, but when the thread exit, object "my" just dealloc.why? even though I change my test code as below - (void)viewDidLoad { [super viewDidLoad]; NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(test) object:nil]; [thread start]; } -(void

Autorelease pools and when release is called under iOS

倖福魔咒の 提交于 2019-11-28 07:02:00
I wanted to get something clarified. Lets say I have the following code: - (void) viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; for (int i = 0; i < 5000000; i++) { NSString *s = [NSString stringWithFormat:@"Hello, %@!", @"World"]; } } This will create 5 million autoreleased strings within this function call. I was expecting this to keep those objects around until the termination of the application, as the only @autoreleasepool I see is the one wrapping the application instantiation in main.m. That's not the case, though. At the end of this function call, it seems they all get

Using ARC, is it fatal not to have an autorelease pool for every thread?

大憨熊 提交于 2019-11-28 04:45:41
I read this: If you ever create a secondary thread in your application, you need to provide it with its own autorelease pool. Autorelease pools and the objects they contain are discussed further in in the iOS 5 Developer cookbook. I'm compiling with ARC. I have been creating many background threads, and it seems that I am doing fine. None of my background threads are long-running. Will all those objects ever be released by say, the main thread's autorelease pool? Or what? This is what I do to call background thread: +(void)doBackground:(void (^)())block { //DISPATCH_QUEUE_PRIORITY_HIGH /

NSThreads in Automatic Reference Counting(ARC)

丶灬走出姿态 提交于 2019-11-28 03:45:37
问题 i am trying to use NSThreads with ARC in 4.3.5. With iOS 5 everything works perfect, but if i try it on a older iOS like 4.3 its leaking. Normally i would use a Autoreleasepool for NSThreads but since there is no manual Autoreleasepool in ARC i don't know how to fix this. I get loads of Messages like "__NSAutoreleaseNoPool(): Object 0x4567b40 of class NSComparisonPredicate autoreleased with no pool in place - just leaking" in my Console after i start a Thread. NSThread detachNewThreadSelector

NSAutoreleasePool is unavailable

牧云@^-^@ 提交于 2019-11-27 22:42:50
I am following "Programming in Objective-C" 3 rd edition and I am having problems with the first example. I keep getting this error: Semantic Issue: 'NSAutoreleasePool' is unavailable: not available in automatic reference counting mode Here is my code: // // main.m // prog1 // // Created by Steve Kochan on 1/30/11. // Copyright 2011 ClassroomM, Inc.. All rights reserved. // #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSLog (@"Programming is fun!"); [pool drain]; return 0; } Any insight will be greatly

does NSThread create autoreleasepool automatically now?

◇◆丶佛笑我妖孽 提交于 2019-11-27 02:22:00
问题 I have test code like this - (void)viewDidLoad { [super viewDidLoad]; NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(test) object:nil]; [thread start]; } -(void)test { MyClass *my = [[[MyClass alloc] init] autorelease]; NSLog(@"%@",[my description]); } I did not create any autoreleasepool for my own thread, but when the thread exit, object "my" just dealloc.why? even though I change my test code as below - (void)viewDidLoad { [super viewDidLoad]; NSThread *thread

Autorelease pools and when release is called under iOS

倖福魔咒の 提交于 2019-11-27 01:40:53
问题 I wanted to get something clarified. Lets say I have the following code: - (void) viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; for (int i = 0; i < 5000000; i++) { NSString *s = [NSString stringWithFormat:@"Hello, %@!", @"World"]; } } This will create 5 million autoreleased strings within this function call. I was expecting this to keep those objects around until the termination of the application, as the only @autoreleasepool I see is the one wrapping the application

Using ARC, is it fatal not to have an autorelease pool for every thread?

荒凉一梦 提交于 2019-11-27 00:38:29
问题 I read this: If you ever create a secondary thread in your application, you need to provide it with its own autorelease pool. Autorelease pools and the objects they contain are discussed further in in the iOS 5 Developer cookbook. I'm compiling with ARC. I have been creating many background threads, and it seems that I am doing fine. None of my background threads are long-running. Will all those objects ever be released by say, the main thread's autorelease pool? Or what? This is what I do to

How does the NSAutoreleasePool autorelease pool work?

拜拜、爱过 提交于 2019-11-26 15:04:13
As I understand it, anything created with an alloc , new , or copy needs to be manually released. For example: int main(void) { NSString *string; string = [[NSString alloc] init]; /* use the string */ [string release]; } My question, though, is wouldn't this be just as valid?: int main(void) { NSAutoreleasePool *pool; pool = [[NSAutoreleasePool alloc] init]; NSString *string; string = [[[NSString alloc] init] autorelease]; /* use the string */ [pool drain]; } kperryua Yes, your second code snippit is perfectly valid. Every time -autorelease is sent to an object, it is added to the inner-most