Domanda

I'm implementing an application in which I use some 'CABasicAnimation'. For example :

myAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
myAnimation.fromValue = [NSNumber numberWithFloat:-5.0f];
myAnimation.toValue = [NSNumber numberWithFloat:744.0f];
myAnimation.duration = t;
myAnimation.repeatCount = 1;
[myUIImageView.layer addAnimation:myAnimation forKey:@"myAnimation"];

When i put this code after :

NSLog(@"Count : %i", myAnimation.retainCount);

it returns me a 1. So I thought i would 'release' the CABasicAnimation.

But when i try to 'release' it, it fails and gives me :

"[CABasicAnimation release]: message sent to deallocated instance 0x8c02a00"

How to fix this error please ?

È stato utile?

Soluzione

The error is occurring because you are releasing an object that is already in an Autorelease Pool. When the pool is drained later, the object is already released, and that's when you get the error you see.

Don't release an object if you didn't create it with alloc or new or copy! In your example code, you don't own myAnimation so you don't need to release it. Period.

Don't look at retainCount unless you are debugging something really weird. That is all it is there for. And in most cases it won't even help you in those situations.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top