Iphone - auto-implemented without a pool in place - just a leak

I have this line in my main code:

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

and this is animateMe

- (void) animateMe {

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

  }];

}

these are the messages that I see on the 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 to solve this?

thank.

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

  }];
  [pool drain];
}
+14
source

This tells you exactly what is wrong - you do not have an autocomplete pool when this selector is executed. You need to add:

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

at the beginning and:

[pool drain];

At the end of your method.

+6
source

-

@autoreleasepool {

//enter code here

}

+1

animateMeexecutes in a new thread since it is called from performSelectorInBackground. Each time you create a thread, this thread must create and reset its own automatic release pool.

From the Apple documentation : "... if you disconnect the stream, you need to create your own autoresist pool block."

0
source

All Articles