Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bluehill

macrumors newbie
Original poster
Feb 5, 2011
22
0
The performance tool is showing leak at this position( red color).

Code:
	NSString *street = [[NSString alloc] initWithString:[dictContact objectForKey:@"add"]];
	NSString *city = [[NSString alloc] initWithString:[dictContact objectForKey:@"city"]];
	NSString *state = [[NSString alloc] initWithString:[dictContact objectForKey:@"state"]];
	NSString *pin = [[NSString alloc] initWithString:[dictContact objectForKey:@"pin"]];
	
[COLOR="Red"]	NSMutableString *address = [[NSMutableString alloc] initWithFormat:@"%@+%@+%@+%@",street,city,state,pin];[/COLOR]
	[address replaceOccurrencesOfString:@" " withString:@"+" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [address length])];
	
	[street release];
	[city release];
	[state release];
	[pin release];

	//NSLog(@"Address %@",address);
	MapViewController *mvController = [[MapViewController alloc]init];
	[mvController setAddress:address];
	[self.navigationController pushViewController:mvController animated:YES];
	[mvController release];

	[address release];
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
The leaks tool doesn't tell you where leaks happened. It tells you where leaked objects were created. The red line is where the leaked string was created.

There's no obvious bug in the code shown. Does anything else leak? Do you release the address in the MapViewController dealloc method? Does the MapViewController leak?
 

bluehill

macrumors newbie
Original poster
Feb 5, 2011
22
0
The leaks tool doesn't tell you where leaks happened. It tells you where leaked objects were created. The red line is where the leaked string was created.

There's no obvious bug in the code shown. Does anything else leak? Do you release the address in the MapViewController dealloc method? Does the MapViewController leak?


Code:
@interface MapViewController : UIViewController <MKMapViewDelegate,NSXMLParserDelegate>
{
    IBOutlet MKMapView *mapView;
	NSURLConnection *updateConnection;
	NSMutableData  *updateData;
	NSData *geoData;
	
	AddressAnnotation *addAnnotation;
	
	NSString *address;
	
	NSMutableDictionary *geoLoc;
	NSMutableString		*workingPropertyString;
	
}

[COLOR="DarkOrange"]@property (nonatomic, retain) IBOutlet MKMapView *mapView;[/COLOR]
.....

When checked the retaincount of mapView it showed count 2 and i had released it only once in dealloc coz of which it was leaking...and now i have released it twice and working fine

why is it showing count 2? Is it the IB has already an instance with it.

When i donot create a property then also it show retaincount 2 but if i release it twice then it crashes.!!!!!:confused:
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
I'm not clear on your explanation. You should always have a property for IBOutlets. You should release the ivar related to the property in dealloc. You shouldn't add an extra release. Is this what you have?
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
And to quote Phoney from a previous thread:

retainCount is often not useful for debugging memory leaks. There are too many objects that work behind the scenes that retain objects and there are also cases where an object is both retained and autoreleased to control the lifetime of the object. It's difficult or impossible to understand all these cases because you don't see all the code.

What you should do is learn the memory management rules. Then use them correctly. Then use build and analyze and the leaks tool to find problems.
 

bluehill

macrumors newbie
Original poster
Feb 5, 2011
22
0
You shouldn't add an extra release. Is this what you have?
Yes


Code:
@synthesize mapView;

- (void)dealloc 
{
	//NSLog(@"Retain cont address=%d geoLoc=%d workingPropertyString=%d mapView=%d",[address retainCount],[geoLoc retainCount],[workingPropertyString retainCount],[mapView retainCount]);
	[updateData release];
	[updateConnection release];
	
	[address release];
	[geoLoc release];
	[workingPropertyString release];
	[mapView release];
    [super dealloc];
}

I deleted the app from the simulator and again Run it with Performance tool now it is not showing any leaks with same old code.... :confused:

Now mapView released only once...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.