views:

144

answers:

1

Hello all,

I have a simple method to read a string and parse it to an array,

-(NSArray *) readFileToArray: (NSString *)file{

NSString *values = [NSString stringWithContentsOfFile: file];

NSArray *tokens = [values componentsSeparatedByString:@":"];

return tokens;

}

however instruments did report me I got a leak on NSString at line NSArray *tokens = [values componentsSeparatedByString:@":"];

I have no idea why this happens, 1). I think both values and tokens are autoreleased? Am I right? 2). I tried to release values and tokens(just a try), it crashes.

Thanks for your help in advance.

Michael

A: 

The code you've posted is using correct memory management (the return value is autoreleased). Look at the code that is calling readFileToArray: to see how it's handling the returned array.

Darren
Darren, Thanks for your answer.