I am repeatedly using the following line of code to load a bunch of plists into a temporary dictionary. The idea is to init the object instance based on user selections in a table list.
But Instrument identifies this line as the source of all leaks. The leak objects being NSCFString and GeneralBlock on a Malloc with the responsible library being Foundations.
Would appreciate any pointers on tackling this. Thanks
Based on your code fragment it looks like everything should be autoreleasing properly. Is this happening on the device or just in the simulator? Sometimes leaks on the simulator can be flaky.
It is on the device. Yes, I thought being a convenience method it should auto release. Every-time I push a new VC I load a new plist and the leaks shows right away in Instrument. Don't understand how the NSCFString come in the picture.
I am repeatedly using the following line of code to load a bunch of plists into a temporary dictionary. The idea is to init the object instance based on user selections in a table list.
But Instrument identifies this line as the source of all leaks. The leak objects being NSCFString and GeneralBlock on a Malloc with the responsible library being Foundations.
Would appreciate any pointers on tackling this. Thanks
Let me know if this works:
Code:
NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:resourceName ofType:@"plist"]];
// use your dict
[tempDict release];
Remember that the leaks tool doesn't tell you where a leak is created. It tells you where the leaked object was created. So this line of code is where the object was created but it's probably leaked somewhere else.
If you have a dictionary then you have strings, either as keys or values in the dictionary. If a value from the dictionary is retained somewhere and never released that would cause this kind of leak.
If the container object itself were leaked then all the keys and values would also be leaked. Is that the case? Is the dictionary leaked? If not, then this line of code is kind of a red herring. The leak is elsewhere.
And I send release message to the entire object so both the ivars ought to get released when I am loading a new plist. Further I believe addObjectsFromArray copies.
Besides tried splitting the line as suggested by Scuba.
Leak profile don't understand just using the Start with Performance tool Leaks in XCode which launches Instruments ObjectAlloc and Leak Tool.
I was missing some releases on strings further down in my layered data model as I pushed down to into VCs. Thank you all for your advice, and listening.