动画占用额外内存

发布于 2024-09-14 00:11:00 字数 529 浏览 7 评论 0原文

我需要在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

囍孤女 2024-09-21 00:11:00

您有多确定动画导致了泄漏?

当您添加/删除没有动画的子视图时会发生什么?泄漏还在吗?

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?

当爱已成负担 2024-09-21 00:11:00

我不确定是否是方法本身增加了内存使用量,但可能是您的视图控制器正在加载?

还可以尝试在动画块中添加这些行,因为我认为这是值得鼓励的(如果我错了,请纠正我)
[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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文