Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iphone - autoreleased with no pool in place - just leaking

Tags:

iphone

I have this line in my main code:

[self performSelectorInBackground:@selector(animateMe) withObject:nil];

and this is the animateMe

- (void) animateMe {

  [UIView animateWithDuration:1.0
     animations:^{
           [myView setAlpha:0.0f];

  }];

}

these are the messages I see on terminal

 *** __NSAutoreleaseNoPool(): Object 0x1af740 of class myClass autoreleased with no pool in place - just leaking
 *** __NSAutoreleaseNoPool(): Object 0x1af740 of class myClass autoreleased with no pool in place - just leaking
 *** __NSAutoreleaseNoPool(): Object 0x1af740 of class myClass autoreleased with no pool in place - just leaking
 *** __NSAutoreleaseNoPool(): Object 0x193190 of class CABasicAnimation autoreleased with no pool in place - just leaking
 *** __NSAutoreleaseNoPool(): Object 0x1b8230 of class NSConcreteValue autoreleased with no pool in place - just leaking
 *** __NSAutoreleaseNoPool(): Object 0x1af740 of class myClass autoreleased with no pool in place - just leaking
 *** __NSAutoreleaseNoPool(): Object 0x1c0ee0 of class CABasicAnimation autoreleased with no pool in place - just leaking
 *** __NSAutoreleaseNoPool(): Object 0x1b4260 of class NSCFNumber autoreleased with no pool in place - just leaking
 *** __NSAutoreleaseNoPool(): Object 0x1aeb30 of class __NSCFDictionary autoreleased with no pool in place - just leaking
 *** __NSAutoreleaseNoPool(): Object 0x1debd0 of class myClass autoreleased with no pool in place - just leaking
 *** __NSAutoreleaseNoPool(): Object 0x1debd0 of class myClass autoreleased with no pool in place - just leaking
 *** __NSAutoreleaseNoPool(): Object 0x1debd0 of class myClass autoreleased with no pool in place - just leaking
 *** __NSAutoreleaseNoPool(): Object 0x1dad90 of class CABasicAnimation autoreleased with no pool in place - just leaking
 *** __NSAutoreleaseNoPool(): Object 0x16db40 of class NSConcreteValue autoreleased with no pool in place - just leaking
 *** __NSAutoreleaseNoPool(): Object 0x1debd0 of class myClass autoreleased with no pool in place - just leaking
 *** __NSAutoreleaseNoPool(): Object 0x1aafc0 of class CABasicAnimation autoreleased with no pool in place - just leaking
 *** __NSAutoreleaseNoPool(): Object 0x1dfc10 of class NSCFNumber autoreleased with no pool in place - just leaking
 *** __NSAutoreleaseNoPool(): Object 0x1d1470 of class __NSCFDictionary autoreleased with no pool in place - just leaking

How do I solve that?

thanks.

like image 846
Duck Avatar asked Jun 16 '11 19:06

Duck


3 Answers

- (void) animateMe {
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  [UIView animateWithDuration:1.0
     animations:^{
           [myView setAlpha:0.0f];

  }];
  [pool drain];
}
like image 75
NWCoder Avatar answered Oct 20 '22 06:10

NWCoder


It's telling you exactly what's wrong - you don't have an autorelease pool in place when that selector gets executed. You need to add:

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

at the beginning, and:

[pool drain];

At the end of your method.

like image 39
Carl Norum Avatar answered Oct 20 '22 07:10

Carl Norum


It may help someone

@autoreleasepool {

//enter code here

}

like image 30
Senthil Avatar answered Oct 20 '22 07:10

Senthil