我有一个下面的代码:
NSLog(@"%d", [chart retainCount]);
self.chart = [[BNPieChart alloc] initWithFrame:self.view.frame];
NSLog(@"%d", [chart retainCount]);终端显示:
[Session started at 2011-03-28 11:09:46 +0200.]
2011-03-28 11:09:51.008 Finance[35111:207] 0
2011-03-28 11:09:51.010 Finance[35111:207] 2据我所知,retainCount应该等于1,而不是2。
发布于 2011-03-28 17:18:03
将定义为保留或复制的属性绘制为图表,因此:
self.chart = [[BNPieChart alloc] initWithFrame:self.view.frame];+1在分配位置保留([BNPieChart alloc])
+1赋值时保留(self.chart = )
发布于 2011-03-28 17:17:28
chart可能是一个保留属性,这就是为什么你有2个retainCount。这就是为什么你可以看到这样的声明:
BNPieChart *aChart = [[BNPieChart alloc] initWithFrame:self.view.frame];
self.chart = aChart;
[aChart release];发布于 2011-03-28 17:17:13
由于语句中的self,其保留计数为2,因为图表的属性被声明为retain Remove self from语句
变化
self.chart = [[BNPieChart alloc] initWithFrame:self.view.frame];至
chart = [[BNPieChart alloc] initWithFrame:self.view.frame];https://stackoverflow.com/questions/5456848
复制相似问题