【发布时间】:2013-03-12 02:12:18
【问题描述】:
从记忆的角度来看,我想知道我所做的是否正确。
首先,我要重用的文件是UIViews 的子类。
在我的UIViewcontroller 中,我声明了一个这样的对象:
World_1_ViewController.h:
#import "Level1.h"
@class Level1;
@interface World_1_ViewController : UIViewController <UIAccelerometerDelegate>
{
Some things....
Level1 * level1view;
}
World_1_ViewController.m:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
level1view = [[Level1 alloc] init];
[self.view addSubview:level1view];
//Other things...
}
当UIViewController World_1_ViewController 打开时,您可以在viewDidLoad 方法中看到它是第一次初始化。
现在我需要重新使用这个对象,level1view,所以在我之后的一个方法中,我使用:
[level1view release];
level1view = [[Level1 alloc] init];
[self.view addSubview:level1view];
//Some methods...
从记忆的角度来看是正确的吗?或者我该怎么办?
【问题讨论】:
标签: ios objective-c memory memory-management