Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-15-2009, 12:50 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 21
Angry NSDictionary leak on loading plists

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.

NSDictionary *tempDict = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:resourceName ofType:@"plist"]];

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
raven is offline   Reply With Quote
Old 03-15-2009, 12:55 PM   #2 (permalink)
Registered Member
 
Join Date: Jul 2008
Location: Minneapolis, MN
Posts: 208
Default

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.
Scuba is offline   Reply With Quote
Old 03-15-2009, 01:17 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 21
Default

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.
raven is offline   Reply With Quote
Old 03-15-2009, 02:48 PM   #4 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 188
Default

Are you using the Leaks profile and not any of the others?

Try breaking the that line into separate statements too.
jsonli is offline   Reply With Quote
Old 03-15-2009, 03:21 PM   #5 (permalink)
Registered Member
 
Join Date: Jul 2008
Location: Minneapolis, MN
Posts: 208
Default

Quote:
Originally Posted by raven View Post
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.

NSDictionary *tempDict = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:resourceName ofType:@"plist"]];

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];
Scuba is offline   Reply With Quote
Old 03-15-2009, 04:03 PM   #6 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

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.
PhoneyDeveloper is offline   Reply With Quote
Old 03-16-2009, 12:03 AM   #7 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 21
Default

Certainly the most plausible explanation PD. I am simply using the following code in the same init method with the scratch dictionary:

totalChapters = [[tempDict objectForKey:@"NumberOfChapters"] intValue];
[chapterList addObjectsFromArray:[tempDict objectForKey:@"Chapters"];

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.
raven is offline   Reply With Quote
Old 03-16-2009, 09:47 AM   #8 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 21
Smile Resolution

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.
raven is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone development, memory leak

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,765
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:23 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0