iPhone内存管理和CATransition

发布于 2024-09-12 04:29:37 字数 1745 浏览 11 评论 0原文

在管理添加和删除 uiviewcontroller 的总内存方面存在一些基本问题 - 但仅当我使用 CAtransition 添加动画时。我在下面的情况下设置了一个简单的场景:

我有一个基本的视图控制器,我将其初始化/分配,称为 IVC,并将其添加到当前的 uiController: 在头文件中,它只是简单地声明:

IntroViewController* IVC;

AT START :3mb 总内存显示在泄漏

3.6mb 总内存

IVC=[[IntroViewController alloc] initWithNibName:@"Intro" bundle:[NSBundle mainBundle]];
[IVC.view setUserInteractionEnabled:YES];   
[self.view addSubview:IVC.view];

中,然后我释放:

[[IVC.view layer] removeAllAnimations];
[IVC.view removeFromSuperview];//remove intro animation
[IVC release];

正如预期的那样,总内存回到 3mb

但当我删除释放代码并添加以下内容时,这样就有是淡入然后释放此处显示的对象:

CATransition *applicationIntroLoadViewIn = [CATransition animation];
[applicationIntroLoadViewIn setDuration:.5];
[applicationIntroLoadViewIn setType:kCATransitionReveal];
[applicationIntroLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[applicationIntroLoadViewIn setValue:@"IntroFadeIn" forKey:@"IntroAnimation"];
[applicationIntroLoadViewIn setDelegate:self];
[[IVC.view layer] addAnimation:applicationIntroLoadViewIn forKey:nil];

然后:

我创建一个方法来处理动画完成时的情况:

- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)flag{
NSString* value = [animation valueForKey:@"IntroAnimation"];

if ([value isEqualToString:@"IntroFadeIn"]){
    //this def gets called NSLog shows up
    [[IVC.view layer] removeAllAnimations];
    [IVC.view removeFromSuperview];//remove intro animation
    [IVC release];
    IVC=nil;
}

没有报告泄漏,视图被删除,但泄漏中内存仍然保留 3.6MB?有什么原因会发生这种情况吗?我不分配动画*,所以我觉得不需要清理,但这表明有些东西仍然保留在我的 IVC 视图中,

非常感谢任何帮助。

Having some basic issues with managing the total memory from adding and removeing a uiviewcontroller - but only when i add an animation to it using CAtransition. I set up a simple scenario below of the situation:

I have a basic view controller that I init/alloc called IVC, and I add to the current uiController:
IN the header file it is simply just declared:

IntroViewController* IVC;

AT START :3mb total memory shown in leaks

3.6mb total memory

IVC=[[IntroViewController alloc] initWithNibName:@"Intro" bundle:[NSBundle mainBundle]];
[IVC.view setUserInteractionEnabled:YES];   
[self.view addSubview:IVC.view];

then i release:

[[IVC.view layer] removeAllAnimations];
[IVC.view removeFromSuperview];//remove intro animation
[IVC release];

as expected here total memory goes back to 3mb

but when i remove the release code and add the following so that there is a fade in and then release the object shown here:

CATransition *applicationIntroLoadViewIn = [CATransition animation];
[applicationIntroLoadViewIn setDuration:.5];
[applicationIntroLoadViewIn setType:kCATransitionReveal];
[applicationIntroLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[applicationIntroLoadViewIn setValue:@"IntroFadeIn" forKey:@"IntroAnimation"];
[applicationIntroLoadViewIn setDelegate:self];
[[IVC.view layer] addAnimation:applicationIntroLoadViewIn forKey:nil];

and then :

i create a method to handle when the animation has finished:

- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)flag{
NSString* value = [animation valueForKey:@"IntroAnimation"];

if ([value isEqualToString:@"IntroFadeIn"]){
    //this def gets called NSLog shows up
    [[IVC.view layer] removeAllAnimations];
    [IVC.view removeFromSuperview];//remove intro animation
    [IVC release];
    IVC=nil;
}

there are no reported leaks, the view is removed , but the memory still stays 3.6MB in Leaks? ANy reason why this would happen? I don't alloc the animation* so i feel that should not need to be cleaned up, but this suggests that something is still holding onto to my IVC view

Any help much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

拥抱我好吗 2024-09-19 04:29:37

在 CATransition 设置代码片段中尝试 applicationIntroLoadViewIn.removedOnCompletion = YES;

Try applicationIntroLoadViewIn.removedOnCompletion = YES; in your CATransition setup code snippet!

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