[2010-10-03]object c中的relese问题

问题:2010-10-03-10:09

虽然object c时知道要谁retain,alloc谁release,dealloc,但是认识并不是很深

ViewController *tempView = [[ViewController alloc] init];
// myViewController已经在@interface定义的ViewController
myViewController = tempViewController;
[tempViewController release];

程序直接崩溃,道理很简单

ViewController *tempView = [[ViewController alloc] init];  // retain = 1
// myViewController已经在@interface定义的ViewController
myViewController = tempViewController; // retain = 1
[tempViewController release];  // retain = 0, 此处出错

但是,如下修改了就没错,Why

// 将myViewController = tempView换成如下的
self.myViewController = tempView   // 只是增加个self

posted on 2010-10-03 10:18  影语者  阅读(243)  评论(0编辑  收藏  举报

导航