views:

431

answers:

2

Hey, i am using this code to animate something

 CATransition *animation = [CATransition animation];
 [animation setDuration:0.45f];
 [animation setType:kCATransitionPush];
 [animation setSubtype:kCATransitionFromRight];
 [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
 [[theWindow layer] addAnimation:animation forKey:@""];
 //[animation release];

I figured i should [release] the animation object when I am done with it, but if i do i get a EXC_BAD_ACCESS in gdb

Program received signal:  “EXC_BAD_ACCESS”.
(gdb) where
#0  0x93c38688 in objc_msgSend ()
#1  0x30506515 in NSPopAutoreleasePool ()
#2  0x305359f0 in __NSFireDelayedPerform ()
#3  0x302454a0 in CFRunLoopRunSpecific ()
#4  0x30244628 in CFRunLoopRunInMode ()
#5  0x32044c31 in GSEventRunModal ()
#6  0x32044cf6 in GSEventRun ()
#7  0x309021ee in UIApplicationMain ()

So i am guessing the I should not release the animation.

Anyone can explain why this is happing? I am used to releasing things and this case is some sort on an exception to this rule. Any thoughts? #8 0x00001d70 in main (argc=1, argv=0xbffff0a4) at

+4  A: 

You do not release this animation as you didn't alloc, new, copy or retain it.

From Cocoa Memory Management Fundamentals:

You take ownership of an object if you create it using a method whose name begins with “alloc” or “new” or contains “copy” (for example, alloc, newObject, or mutableCopy), or if you send it a retain message. You are responsible for relinquishing ownership of objects you own using release or autorelease. Any other time you receive an object, you must not release it.

nall
thanks. got it.
Nir Levy
+2  A: 

The CAAnimation is being autoreleased automatically because you are using the Class Method for CAAnimation.

You are not liable for releasing it, it will be released at the end of the runloop automatically.

wildwobby
Just to be explicit about terminology, it's not the fact that the OP is calling a "class method" that obviates the need for a call to release. It's the name of the particular class method. For instance, alloc is also a class method and a value returned from it would have to be released.
nall