I've gone thru my app using build/analyze and been able to resolve all issues.
but running under leak tool it detects a leak and says it comes from tvc:viewDidLoad where tvc is a tableViewController
it further references NSArray -> sectionlist
it shows a malloc refct=1 then a retain refct=2 then a release refct=1
here is viewDidLoad below followed by the dealloc and the header
I don't see where this is a problem? Am I missing something?
other than the code I've included, the sectionList is only referenced in 2 other places -
in numberOfRowsInSection
return [[self sectionList] count];
in cellForRowAtIndexPath
[[cell textLabel] setText:[[self sectionList] objectAtIndex:indexPath.row]];
is this a red herring? ie; is it a real leak or is the leak tool only capable of showing the alloc but then not showing where the release happens in the dealloc when the tvc is unloaded later?
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];开发者_StackOverflow中文版
}
//////// header
////////////////////////////////////////
#import <UIKit/UIKit.h>
@interface tvc : UITableViewController
{
NSArray *ivsectionList;
}
@property (nonatomic, retain) NSArray *sectionList;
@end
////////////////////////////////////////
leaks (or Instruments) is telling you where the leaked object is created.
most likely, a client is not releasing it.
a subclass may also be misusing this class, it's a good idea to make your ivars @private
by default.
alternatively, you may want to try atomic
read/write, just in case you're having a threading issue in this case.
(but yes, the excerpt looks correct)
精彩评论