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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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 06-30-2010, 11:33 PM   #1 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 11
surgen12 is on a distinguished road
Default Leak Problem with [NSMutableArray removeAllObjects];

Hey Guys

I have leak problem here.
The Instrument that checks leak
says there is leak with code below.


[self.artRecords_list removeAllObjects];

[self.artRecords_list release];


self.artRecords_list = [[NSMutableArray alloc] init];

while(sqlite3_step(statement) == SQLITE_ROW)
{

self.ArtInfo = [[ArtRecord alloc] init]; // <- This is leaking point.

char * str_empty = (char * )sqlite3_column_text(statement,0);
if(str_empty != NULL)
{
self.ArtInfo.art_title = [NSString stringWithUTF8Stringchar * )sqlite3_column_text(statement,0)];
self.ArtInfo.part_title = [NSString stringWithUTF8Stringchar * )sqlite3_column_text(statement,1)];

[self.artRecords_list addObject:self.ArtInfo];
//[self.ArtInfo autorelease];
//[self.ArtInfo release];


}


Yes I need to make a list of Object that contains some information.
So I decided make NSMutableArray and I fill it with this Object.

and it says there is Leak.
I added some code like:
//[self.ArtInfo autorelease];
//[self.ArtInfo release];
these.

and It crashes.
Wherever point I put "release" code It crashes.

But I can't find any other way to make list of objects dynamically.

please help.

Thanks in advance.
surgen12 is offline   Reply With Quote
Old 07-01-2010, 12:22 AM   #2 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 107
JDave is on a distinguished road
Default

Without looking at all the code (AND/OR knowing the specific error you are getting), I would guess that ArtInfo is a global variable (ie, you declared it in your .h file, and synthesize it in your .m, right?). If so, then you set it to nil and release it in viewDidUnload: (iOS4 methods aside...) and dealloc:, respectively... Releasing it inside the run loop will cause uncertain results, depending on the retain count... which is likely 0 when you release it. To check if it is a retain count issue, do this:

Code:
[ArtInfo retain]; // retain count now +1
[ArtInfo release]; // without the above code, this line will cause a 'crash'
Try 'build and analyze' (in BUILD menu of XCODE).... it sometimes gives more info than leaks, IMHO.

ALSO, look at how you create your ArtRecord class (the .h/.m), it may be leaky, too.

Good Luck.

Last edited by JDave; 07-01-2010 at 12:32 AM.
JDave is offline   Reply With Quote
Old 07-01-2010, 01:25 AM   #3 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 342
flamingliquid is on a distinguished road
Default

Is you artInfo property set to retain? If so, then that is why it is leaking. Check out this link:

http://www.iphonedevsdk.com/forum/ip...roperties.html
__________________
17 year old nerd.
Send me a PM. Maybe I can help.
flamingliquid is offline   Reply With Quote
Old 07-01-2010, 08:26 PM   #4 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 11
surgen12 is on a distinguished road
Default Thank you guys.

I will try .
surgen12 is offline   Reply With Quote
Old 07-01-2010, 08:51 PM   #5 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 11
surgen12 is on a distinguished road
Default I start suspecting this instrument.

I tried below.

Code:
[ArtInfo retain]; // retain count now +1
[ArtInfo release]; // without the above code, this line will cause a 'crash'
I put this code upper part of the while loop like below.

while(sqlite3_step(statement) == SQLITE_ROW)
{
if (ArtInfo != nil) {
//ArtInfo = nil;
[ArtInfo retain];
[ArtInfo release];

}


ArtInfo = [[ArtRecord alloc] init];

char * str_empty = (char * )sqlite3_column_text(statement,0);
if(str_empty != NULL)
{

ArtInfo.art_title = [NSString stringWithUTF8Stringchar * )sqlite3_column_text(statement,0)];
ArtInfo.part_title = [NSString stringWithUTF8Stringchar * )sqlite3_column_text(statement,1)];

[self.artRecords_list addObject:ArtInfo];
}
else
{
self.str_cnt = @"0";
}
}


There was no crash and it appeared working well.

but the instrument pointed the same leak again.
so according to this code it release every ArtInfo that created
and It is not retain variable it is global variable declared in .h file.

I think this 'Leak instrument' isn't so perfect.
surgen12 is offline   Reply With Quote
Old 07-08-2010, 08:18 PM   #6 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 11
surgen12 is on a distinguished road
Default I got it solved.

Recently I purchased a book, named "Advanced iPhone Develop..." something like that.

and I found that they use NSMutableDictionary for this kind job.

So I stopped using my own class "ArtRecord" for this job and I used NSMutableDictionary.

And It worked so well.

No leak for this job.

My Custom class "ArtRecord" was the problem.
I still have no idea why it didn't work for this job it did work with NSMutableDictionary.

May be some special skill for this sdk utility class.

Anyway Nice experience.

Thank you all of you.
surgen12 is offline   Reply With Quote
Reply

Bookmarks

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
» Online Users: 330
7 members and 323 guests
anothermine, Chickenrig, Domele, givensur, michaelhansen, PixelInteractive, Sloshmonster
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,892
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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