【发布时间】:2010-10-25 17:15:05
【问题描述】:
我已经使用 build/analyze 完成了我的应用程序,并且能够解决所有问题。
但在泄漏工具下运行它会检测到泄漏并说它来自 tvc:viewDidLoad 其中 tvc 是一个 tableViewController
它进一步引用了 NSArray -> sectionlist
它显示了一个 malloc refct=1 然后保留 refct=2 然后发布 refct=1
下面是 viewDidLoad,后面是 dealloc 和 header
我看不出问题出在哪里?我错过了什么吗?
除了我包含的代码之外,sectionList 仅在其他 2 个地方引用 -
-
in numberOfRowsInSection
return [[self sectionList] count];
-
在 cellForRowAtIndexPath 中
[[cell textLabel] setText:[[self sectionList] objectAtIndex:indexPath.row]];
这是一条红鲱鱼吗? IE;是真正的泄漏还是泄漏工具仅能够显示分配,但在稍后卸载 tvc 时无法显示释放在 dealloc 中发生的位置?
enter code here
/// code
////////////////////////
// property
@synthesize sectionList = ivSectionList;
/*
*********************************************
build list of sections
*********************************************
*/
- (void)viewDidLoad
{
[super viewDidLoad];
// alloc a local array and init with values
NSArray *sections = [[NSArray alloc] initWithObjects:@"A", @"B", @"C", nil];
// assign local array to tvc ivar
[self setSectionList:sections];
// release local array
[sections release], sections=nil;
}
/*
*********************************************
release ivSectionList
*********************************************
*/
- (void)dealloc
{
[ivsectionList release], ivsectionList=nil;
[super dealloc];
}
//////// header
////////////////////////////////////////
#import <UIKit/UIKit.h>
@interface tvc : UITableViewController
{
NSArray *ivsectionList;
}
@property (nonatomic, retain) NSArray *sectionList;
@end
////////////////////////////////////////
【问题讨论】:
标签: xcode memory-leaks