I have the following error message in my log:
2011-10-13 10:41:44.504 Provision[386:6003] *** __NSAutoreleaseNoPool(): Object 0x4e0ef40 of class CABasicAnimation autoreleased with no pool in place - just leaking
2011-10-13 10:41:44.505 Provision[386:6003] *** __NSAutoreleaseNoPool(): Object 0x4b03700 of class NSConcreteValue autoreleased with no pool in place - just leaking
2011-10-13 10:41:44.506 Provision[386:6003] *** __NSAutoreleaseNoPool(): Object 0x4b04840 of class __NSCFDictionary autoreleased with no pool in place - just leaking
The error message occur when I run the following code.
CGRect newFrame = [viewTop frame];
newFrame.origin.x = 0;
newFrame.origin.y = 0;
[UIView beginAnimations:@"nil1" context:nil];
[UIView setAnimationDuration:0.3f];
[viewTop setFrame:newFrame];
[UIView commitAnimations];
Any insight? Thank you for your kindness
This is happening because you are using autoreleased objects when there is no autorelease pool present. You can read more about NSAutoreleasePool here.
In your cocoa development you may have seen expressions like these:
All of these make use of the autorelease pool. In the first two cases, an
autorelease
message is sent to the objects for you. In the last case, we send it to the object explicitly. Theautorelease
message says "decrement the reference count when the closest autorelease pool is drained." Here is an example:As you might imagine, there can be memory leaks if you
autorelease
an object expecting the pool to release it later. Cocoa detects this and throws the error you posted above.Typically in Cocoa programming, an
NSAutoreleasePool
is always available. TheNSApplication
's run loop drains it at every iteration. However, if you are doing work outside the main thread (i.e., if you created your own thread) or if you are doing work before callingNSApplicationMain
or[NSApp run]
, there won't be an autorelease pool in place. You can usually fix this by adding one: