Can any one identify the leak???

Discussion in 'iOS Programming' started by bluehill, May 2, 2011.

  1. macrumors newbie

    Feb 5, 2011
    The performance tool is showing leak at this position( red color).

    	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];
  2. macrumors 68030


    Sep 2, 2008
    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?
  3. thread starter macrumors newbie

    Feb 5, 2011

    @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:
  4. macrumors 68030


    Sep 2, 2008
    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?
  5. Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    And to quote Phoney from a previous thread:

  6. thread starter macrumors newbie

    Feb 5, 2011

    @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...

Share This Page