Do I need autorun if I do not create auto-implemented objects?

I mean, if I was absolutely sure that I did not create any auto-implemented objects, then, of course, this is not so. My real concern is if something else under the hood I do not understand. I have a background thread that calls a function. Should I always create an auto-advertisement pool?

- (void)someFuncOnABackgroundThread { //don't seem to need this. no leaks found NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; //do something that doesn't create any objects, or only use alloc/init/release NSString* str = [[NSString alloc] init]; [str release]; [pool drain]; } 
+7
source share
2 answers

ultimately, it depends on the interfaces you use in the implementation.

example 1

if you interact with Foundation or other types of objc, you should. no questions.

to answer the specific example that you posted: definitely create one in this case - the NSString apis should assume that the autocomplete pool is in place.

example 2

if you are fully using apis in libc there is no need.

bottom row

  • it may take a long time to figure out where it is needed (or not).

  • the implementation may change, and they may introduce objects with auto-implementation.

  • you must ensure that the leak is never introduced, especially for such a simple reason.

  • This is a simple problem to overcome: if in doubt, create one.

+1
source

Oops! You should. You might be calling a function that internally uses autocomplete pools, so you never know if you are using autoadvertising or not.

Good luck

+3
source

All Articles