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 07-27-2009, 02:46 AM   #26 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Australia
Posts: 180
Default

Quote:
Originally Posted by BrianSlick View Post
Code:
// declare array
[self setFieldDataArray:[[NSMutableArray alloc] init]];
[self setSectionArray:[[NSMutableArray alloc] init]];
These are leaks. Never do alloc/init in the same line as you assign a property. It should be three lines, like this:

Code:
NSMutableArray *fieldArray = [[NSMutableArray alloc] init];
[self setFieldDataArray: fieldArray];
[fieldArray release], fieldArray = nil;
Code:
// name 
NSString *trackName = [[self trackDict] objectForKey:kNameKey];
if (trackName == nil) 
   trackName = @"";
[[self fieldDataArray] addObject:trackName];
[self setNameText:trackName];
[trackName release];
I'm going to say that's the problem. trackName is autoreleased.


By the way, comment "when i click "back button" on the navigationcontroller" would have been a useful piece of information before. That's most likely when the autorelease pool is getting drained. I thought you meant you were literally crashing at the aforementioned line of code.

I have fixed the things you said, but when i try to release trackDictionary, it still crashes when i click "back button". very weird.

but if i dont release it, its fine.
svveet is offline   Reply With Quote
Old 07-27-2009, 09:42 AM   #27 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

Well, I don't know what else to tell you. Probably time for you to do to a thorough review of your code, line by line, and double check all of the little things we've talked about in this thread. Release if you did an alloc/init, don't if you didn't, etc.

I just don't see how trackDictionary can be an autoreleased object, so I'm almost positive the problem is somewhere else.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 07-27-2009, 11:44 AM   #28 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 536
Default

Quote:
Originally Posted by svveet View Post
I have fixed the things you said, but when i try to release trackDictionary, it still crashes when i click "back button". very weird.

but if i dont release it, its fine.
So I don't think the problem is that you are over-releasing the dictionary. The problem is you are over-releasing items in the dictionary. By not releasing the dictionary itself, you are just masking the problem.

For example look at this:

Code:
NSMutableArray *triparray = [[self trackDict] objectForKey:kTripKey];
		[self setCurrentTrackTripArray:triparray];
		[triparray release]; // You shouldn't be doing this.
You don't want to be releasing triparray there. There may be other cases of this as well, so if you clean those up then you should be able to release the dictionary after setTrackDict, which is the right thing to do.

Hope that helps. If not, please post the current version of the code including all the new changes you've incorporated.
eddietr is offline   Reply With Quote
Old 07-27-2009, 07:22 PM   #29 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Australia
Posts: 180
Default

Quote:
Originally Posted by eddietr View Post
So I don't think the problem is that you are over-releasing the dictionary. The problem is you are over-releasing items in the dictionary. By not releasing the dictionary itself, you are just masking the problem.

For example look at this:

Code:
NSMutableArray *triparray = [[self trackDict] objectForKey:kTripKey];
		[self setCurrentTrackTripArray:triparray];
		[triparray release]; // You shouldn't be doing this.
You don't want to be releasing triparray there. There may be other cases of this as well, so if you clean those up then you should be able to release the dictionary after setTrackDict, which is the right thing to do.

Hope that helps. If not, please post the current version of the code including all the new changes you've incorporated.
Yes you are absolutely right! you have fixed my problem. thanks alot for all.
triparray should be autoreleased, isnt it.
svveet is offline   Reply With Quote
Old 07-27-2009, 08:02 PM   #30 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 536
Default

Quote:
Originally Posted by svveet View Post
Yes you are absolutely right! you have fixed my problem. thanks alot for all.
triparray should be autoreleased, isnt it.
Well, it's not really autoreleased here, because objectForKey doesn't retain it. So there is no need to autorelease it. And no need for you to release it either.
eddietr is offline   Reply With Quote
Old 08-18-2009, 12:28 AM   #31 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Australia
Posts: 180
Default

I have another problem releasing objects issue, its bothering me.

when i try to release an NSMutableArray object, if i release it, it crashes.

I just want to know if i added NSMutableArray to another NSMutableArray, do i release both of them? or just 1?

Here is the code:
Code:
if (isNewTrip) {
		NSMutableArray *emptyarray2 = [[NSMutableArray alloc] init]; 
		[self setRecordXYArray:emptyarray2];
		[self setRecordShopArray:emptyarray2];
		[emptyarray2 release];   // somehow when i tried to release emptyarray2, it crashes. 
	}
	
	NSMutableArray *singleXYPoint = [[NSMutableArray alloc] init]; 
	NSNumber *pLat = [[NSNumber alloc]initWithDouble:shopLatitude];
	NSNumber *pLong = [[NSNumber alloc]initWithDouble:shopLongtitude];
	
	// Timestamp
	NSDate *date = [NSDate date];
	NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init]  autorelease];
	[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
	[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
	[dateFormatter stringFromDate:date];
	[dateFormatter setDateFormat:@"dd/MM/yyyy H:m:ss"];
	NSString *testDate = [dateFormatter stringFromDate:[NSDate date]];
	
	NSNumber *horAccuracy = [[NSNumber alloc]initWithFloat:-1.0];
	
	[singleXYPoint addObject:pLat];
	[singleXYPoint addObject:pLong];
	[singleXYPoint addObject:testDate];
	[singleXYPoint addObject:date];
	[singleXYPoint addObject:horAccuracy];
	
	[recordXYArray addObject:singleXYPoint]; 

	[singleXYPoint release];
svveet is offline   Reply With Quote
Old 08-18-2009, 12:39 AM   #32 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

You are adding the same emptyarray2 to two different properties. I'm guessing that you will want a separate array - emptyarray3? - for each one.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 08-18-2009, 07:56 AM   #33 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Long Beach, CA
Posts: 612
Send a message via AIM to bytor99999 Send a message via Yahoo to bytor99999
Default

I found on iTunes, the Stanford University iPhone class videos to be very helpful. They have a great one which deals with memory and releasing object that really cleared up a lot for me.

If you go to iTunes, I think a search on Stanford and iPhone should return those videos.

Mark
__________________
Perfect World Programming LLC
http://www.perfectworldprogramming.com

Please check out my apps.

TubeOrganizer
http://www.spritzlerapps.com/tube-organizer.html

Paper Clips
http://spritzlerapps.weebly.com/paper-clips.html
bytor99999 is offline   Reply With Quote
Reply

Bookmarks

Tags
memory management, memory problem, release

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: 236
16 members and 220 guests
ADY, Alsahir, cacao, dacapo, Dani77, Desert Diva, djohnson, F_Bryant, HemiMG, jansan, M@realobjects, MarkC, prchn4christ, smethorst, spiderguy84
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,882
Threads: 89,228
Posts: 380,762
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jansan
Powered by vBadvanced CMPS v3.1.0

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