动画占用额外内存
我需要在我的 iPad 应用程序中使用动画。当我使用动画时,内存增加并出现异常。当我启动应用程序时,内存大小为 10 mb,一旦动画启动,内存大小就会增加到发射空间的两倍(30 MB)。我测试了分配和泄漏,一切都很完美,但仍然遇到了这个问题。我不知道为什么会这样。我的动画代码如下。请帮助我。
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
if ([currentView superview])
{
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:mainView cache:YES];
[currentView removeFromSuperview];
[mainView addSubview:nextView];
}
[UIView commitAnimations];
提前致谢, 塞卡尔·贝塔拉姆。
I need to use animation in my iPad application.When I use the animations the memory is increasing and getting exception..When I launch my application the size of the memory is 10 mb, once the animations are started it is increasing the memory size upto double of the launch space (it is 30 mb). I test for the allocations and leaks everything is perfect but still I got this problem. I don't know why it is happening. My animation code is as follows.Please help me.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
if ([currentView superview])
{
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:mainView cache:YES];
[currentView removeFromSuperview];
[mainView addSubview:nextView];
}
[UIView commitAnimations];
Thanks in advance,
Sekhar Bethalam.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您有多确定动画导致了泄漏?
当您添加/删除没有动画的子视图时会发生什么?泄漏还在吗?
nextView
在哪里初始化/释放?if ([currentView superview])
到底要检查什么,因为我认为它总是返回 True?How sure are you that the animation is causing the leak?
What happens when you add/remove subviews without the animation? Is the leak still there?
Where is
nextView
initialized/released?What exactly is
if ([currentView superview])
meant to check for because I think it'll always return True?我不确定是否是方法本身增加了内存使用量,但可能是您的视图控制器正在加载?
还可以尝试在动画块中添加这些行,因为我认为这是值得鼓励的(如果我错了,请纠正我)
[currentView viewWillAppear:YES];
[currentView viewDidAppear:YES];
[mainView viewWillDisappear:YES];
[mainView viewDidDisappear:YES];
另外我相信 setAnimationTransition 现在在 IOS4 中不鼓励使用,所以也许尝试使用
+ (void)transitionWithView:(UIView *)视图持续时间:(NSTimeInterval)持续时间选项:(UIViewAnimationOptions)选项动画:(void (^)(void))动画完成:(void (^)(BOOL finish))完成
I'm not sure if it's the method itself that is increasing the memory usage but likely your view controller that's being loaded in?
Also try adding these lines in your animation block as I think it's encouraged (please correct me if I am wrong)
[currentView viewWillAppear:YES];
[currentView viewDidAppear:YES];
[mainView viewWillDisappear:YES];
[mainView viewDidDisappear:YES];
Also I believe setAnimationTransition is now discouraged in IOS4 so maybe try using
+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion