From: Panayotis K. <pan...@pa...> - 2010-03-25 16:43:18
|
On xml...@li...25 Μαρ 2010, at 6:27 μ.μ., Joshua Melcon wrote: > Last time I was digging through the OBJ-C documentation about AutoReleasePools I recall seeing something that indicated that the runtime generally creates one before it invokes a thread. That said, I do have the following code in java_lang_Thread.m for a reason: > > - (void) threadCallback: (id) arg > { > NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; > [runnable run__]; > [self release]; > [pool release]; > } > Because apparently, at least in certain cases, you are responsible for creating the pool... > > The above pattern, plus the assumption that the runtime creates pools as necessary should prevent any problems. > > Let me know if you have any issues… Not really, have a look here: http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSAutoreleasePool_Class/Reference/Reference.html If you are making Cocoa calls outside of the Application Kit’s main thread—for example if you create a Foundation-only application or if you detach a thread—you need to create your own autorelease pool. That's why I am asking that. But in any case, I have seen this code and it seems that it should work. I did some preliminary tests and I didn't experience any problems. I just want to make sure that you are aware of this situation. |