2

I recently switched to ARC for my app project. I'm using iOS 5 SDK. Running one iPod 4g device I don't get any warnings. But trying to run my app on iPod 2g I get many warnings:

*** __NSAutoreleaseNoPool(): Object 0x258070 of class DataModel autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x2530a0 of class __NSArrayM autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x25a2e0 of class NSCFNumber autoreleased with no pool in place - just leaking

I guess there's difference between running arm6/arm7 code by using ARC.

How to fix this ? Thanks

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
kesrut
  • 662
  • 1
  • 9
  • 25

1 Answers1

5

Wherever you are doing stuff on a separate thread, it'd be smart to add @autoreleasepool contexts.

More information available here.

There's also some decent examples to be found in this related question.

Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • After I switched app to ARC, I removed all autorelease pools. I have just one autorelease pool in main.m file. For ARC code I think there's not any requirement to use autorelease pools. Does i'm right ? – kesrut Dec 26 '11 at 12:17
  • So I need convert all NSAutoreleasePool constructions to @autoreleasepool ? That's bad because i removed all NSAutoreleasePool constructions from my code ... – kesrut Dec 26 '11 at 12:29
  • Nope. You still need to keep things in `@autoreleasepool` contexts (or `NSAutoreleasePool` should work fine as well... the newer form I think came in with ARC but they should be equivalent, IMO). [This related question is rather wordy](http://stackoverflow.com/questions/8364853/objective-c-autoreleasepool-arc-automatic-reference-counting), but it should provide some more technical detail. – Michael Dautermann Dec 26 '11 at 12:30
  • @kesrut - That's a good reason to start using version control. – Abizern Dec 26 '11 at 13:01
  • @kesrut - As Michael states, anything run on a background thread still needs to be wrapped in an `@autoreleasepool`, because only the main thread has an autorelease pool by default. Otherwise, you leak autoreleased objects, as the error indicates. The one exception to this is that [blocks in GCD do not require explicit autorelease pools](http://stackoverflow.com/questions/4141123/do-you-need-to-create-an-nsautoreleasepool-within-a-block-in-gcd), which is another good reason to use GCD instead of manual threads. – Brad Larson Dec 26 '11 at 19:11