简体   繁体   中英

Animations make my app crash: How can I remove them?

In my app, I create view controller objects as I need them. When a view controller goes away, I get rid of it by calling -removeFromSuperview on it's view and then set the retaining property to nil.

That way my app uses very low memory all the time. But there's a problem: I have heavy animations going on in some view controllers, and every animation always has an animation delegate which is self. Now the thing that happens is: When there are animations running and I drop the view controller, it goes away - and at some point when one of those animations finishes it seems to crash.

So the question is: How to remove any running animation from a view and all it's subviews?

Agreed. There may be some confusion on how you add/remove the subview, and how you retain/release it. Make sure that you are following these guidelines:

// To add
AView * aSubView = [[AView alloc] init];
[aContainerView addSubview:aSubView];
[aSubView release]; // aSubView is retained by aContainerView

... and later on

// To remove
[aSubView removeFromSuperview]; // and nothing else!

Do not do this:

[self removeFromSuperview]; // Don't cut the branch on which you are sitting

(you already knew that!)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM