Hi all,
I am running the following code which reads a simple csv file and then creates an object for each line and sets one value. When I run the code in instruments using leaks it creates a leak (NSCFString) for each line in the csv. I cannot understand how to stop this leak?
The leak shows up when I do
if I replace this line with
then there is no leak?
I am running the following code which reads a simple csv file and then creates an object for each line and sets one value. When I run the code in instruments using leaks it creates a leak (NSCFString) for each line in the csv. I cannot understand how to stop this leak?
Code:
- (void)viewDidLoad {
[super viewDidLoad];
buildingsArray = [[NSMutableArray alloc] init];
//BUILDINGS
NSBundle *bundle = [NSBundle mainBundle];
NSString *fileContents = [NSString stringWithContentsOfFile:
[bundle pathForResource:@"buildings" ofType:@"csv"]];
NSMutableArray *quizArray = [[NSMutableArray alloc]
initWithArray:[fileContents componentsSeparatedByString:@"\n"]];
for (int i = 0; i < [quizArray count]; i++) {
NSMutableArray *chunks = [[NSMutableArray alloc]
initWithArray:[[quizArray objectAtIndex:i] componentsSeparatedByString:@","]];
Building *a = [[Building alloc]init];
//the problem shows up here
a.name = [chunks objectAtIndex: 0];
[buildingsArray addObject:a];
[a release];
[chunks release];
}
[quizArray release];
}
The leak shows up when I do
Code:
a.name = [chunks objectAtIndex: 0];
Code:
a.name = @"test";