【问题标题】:How to deal with a property memory management in IOS?如何处理IOS中的属性内存管理?
【发布时间】:2012-01-10 09:51:45
【问题描述】:

在我的应用程序中,我有一个 IBAction 方法可以将视图更改为另一个视图:

-(IBAction)beginGame:(id)sender { NSLog(@"开始游戏点击"); GameView * thisGameView = [[[GameView alloc] init]; MainAppDelegate * 委托 = (MainAppDelegate *) [[ UIApplication sharedApplication] 委托]; delegate.window.rootViewController = thisGameView; }

我应该如何处理 rootViewController 属性和 thisGameView 内存管理? 现在发布这个GameView?

请在这个“beginGame”方法中填写一些代码。谢谢。

【问题讨论】:

    标签: iphone objective-c ios memory-management


    【解决方案1】:

    如果rootViewController属性是retain属性,那么可以在行后释放thisGameView实例:

    delegate.window.rootViewController = thisGameView;
    

    【讨论】:

    • 非常感谢,我发现 rootViewController 是保留:@property(nonatomic,retain) UIViewController *rootViewController __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0); // 默认为零
    • 这就是我在回答中告诉你的。 :)
    【解决方案2】:

    是的,您应该在将thisGameView 分配给delegate.window.rootViewController 后释放它。作业将保留它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-19
      • 2011-11-19
      • 1970-01-01
      • 2015-10-04
      • 2018-02-18
      • 1970-01-01
      相关资源
      最近更新 更多