【发布时间】:2012-06-02 22:15:45
【问题描述】:
在使用分析构建运行应用程序时,Xcode 发现我有很多内存泄漏,特别是有一个我不知道如何解决它:
- (UIView *) tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section {
UIImageView *sectionImage = [[UIImageView alloc] init];
if (section == 0)sectionImage.image = [UIImage imageNamed:@"myImage.png"];
return sectionImage;
}
所以我的问题是,我怎样才能发布这个sectionImage? if是方法的return?
编辑:
我还有一个问题,分析给我另一个内存泄漏,我有这个:
.h @property(非原子,保留)NSIndexPath *directCellPath;
.m
@synthesize directCellPath = _directCellPath;
- (id)init{
if ((self = [super initWithNibName:@"MyViewController" bundle:nil])) {
self.directCellPath = [[NSIndexPath alloc] init];
}
return self;
}
然后在代码中我使用它,最后在 dealloc 中我这样做:
- (void)dealloc {
[_directCellPath release];
[super dealloc];
}
并在这一行给我一个内存泄漏:
self.directCellPath = [[NSIndexPath alloc] init];
如果我在 dealloc 中释放了它,为什么?
【问题讨论】:
标签: iphone ios memory-leaks