{"id":4062,"date":"2014-03-30T07:25:59","date_gmt":"2014-03-30T07:25:59","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/where-is-the-leak-collection-of-common-programming-errors\/"},"modified":"2014-03-30T07:25:59","modified_gmt":"2014-03-30T07:25:59","slug":"where-is-the-leak-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/where-is-the-leak-collection-of-common-programming-errors\/","title":{"rendered":"Where is the leak?-Collection of common programming errors"},"content":{"rendered":"<p>I don&#8217;t get it! Instruments is showing me a leak in this method<\/p>\n<pre><code>-(void)loadData\n{\n\n\nif (locationData != nil) {\n        [locationData release];\n    }\n\n\nself.locationData = [[NSMutableArray alloc] init];\n\nNSData *recievedData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@\"http:\/\/htmlwin001.******.net\/blutalkasp\/locations2.asp?uid=%@&amp;von=%d&amp;bis=%d\", [[UIDevice currentDevice] uniqueIdentifier], von, bis]]];\n\nNSString *recievedString = [[NSString alloc] initWithData:recievedData encoding:NSUTF8StringEncoding];\n\nSBJsonParser *json = [[SBJsonParser alloc] init];\nNSMutableDictionary *jsonData = [json objectWithString : recievedString];\n\nNSString *tmpLocationData;\nfor (NSDictionary *location in [jsonData objectForKey:@\"items\"]) {\n    Location *newLocation = [[Location alloc] init];\n    tmpLocationData = [[NSString alloc]initWithFormat:@\"%@\", [location objectForKey:@\"id\"]];\n    [newLocation setLocationID:tmpLocationData];\n    [tmpLocationData release];\n    tmpLocationData = [[NSString alloc]initWithFormat:@\"%@\", [[location objectForKey:@\"locationname\"] gtm_stringByUnescapingFromHTML]];\n    [newLocation setLocationName:tmpLocationData];\n    [tmpLocationData release];\n    tmpLocationData = [[NSString alloc]initWithFormat:@\"%@\",[location objectForKey:@\"locationdistance\"]];\n    [newLocation setLocationDistance:tmpLocationData];\n    [tmpLocationData release];\n    tmpLocationData = [[NSString alloc]initWithFormat:@\"%@\", [[location objectForKey:@\"locationaddress\"] gtm_stringByUnescapingFromHTML]];\n    [newLocation setLocationAdress:tmpLocationData];\n    [tmpLocationData release];\n    tmpLocationData = [[NSString alloc]initWithFormat:@\"%@\", [[location objectForKey:@\"locationdescription\"] gtm_stringByUnescapingFromHTML]];\n    [newLocation setLocationDescription:tmpLocationData];\n    [tmpLocationData release];\n\n    NSNumber *tmpLocationLat = [[NSNumber alloc] initWithInteger:[[location objectForKey:@\"locationlatitude\"]integerValue]];\n    [newLocation setLocationPositionLat:tmpLocationLat];\n    [tmpLocationLat release];\n\n    NSNumber *tmpLocationLng = [[NSNumber alloc] initWithInteger:[[location objectForKey:@\"locationlongitude\"]integerValue]];\n    [newLocation setLocationPositionLng:tmpLocationLng];\n    [tmpLocationLng release];\n\n    NSString *URL;\n    URL = [location objectForKey:@\"locationimage1\"];\n    URL = [URL stringByReplacingOccurrencesOfString:@\"[SLASH]\" withString:@\"\/\"];\n    NSString *tmpUrl1 = [[NSString alloc]initWithFormat:@\"http:\/\/htmlwin001.******.net\/blutalkasp\/locationimages\/data\/%@\", URL];\n    [newLocation setLocationImageURL1:tmpUrl1];\n    [tmpUrl1 release];\n\n    URL = [location objectForKey:@\"locationimage2\"];\n    URL = [URL stringByReplacingOccurrencesOfString:@\"[SLASH]\" withString:@\"\/\"];\n    NSString *tmpUrl2 = [[NSString alloc]initWithFormat:@\"http:\/\/htmlwin001.******.net\/blutalkasp\/locationimages\/data\/%@\", URL];\n    [newLocation setLocationImageURL2:tmpUrl2];\n    [tmpUrl2 release];\n\n    URL = [location objectForKey:@\"locationimage3\"];\n    URL = [URL stringByReplacingOccurrencesOfString:@\"[SLASH]\" withString:@\"\/\"];\n    NSString *tmpUrl3 = [[NSString alloc]initWithFormat:@\"http:\/\/htmlwin001.******.net\/blutalkasp\/locationimages\/data\/%@\", URL];\n    [newLocation setLocationImageURL3:tmpUrl3]; \/\/Leak geschlossen\n    [tmpUrl3 release];\n\n    [self.locationData addObject:newLocation];\n\n    [newLocation release];\n}   \n[recievedString release];\n[json release];\n\n}\n<\/code><\/pre>\n<p>Is it possible that [nsdictionaryobject objectForKey:@&#8221;xy&#8221;]; is causing a leak? Becaus in instrument espeacially these lines are coloured. As you can see I was releasing everything. I&#8217;m quite desperate with that app. I even began to replace all the convenient constructors through alloc\/init..\/release. e.g. &#8230;initWithFormat instead of stringWithFormat&#8230; Especially in loops! But sometimes even instruments crash!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I don&#8217;t get it! Instruments is showing me a leak in this method -(void)loadData { if (locationData != nil) { [locationData release]; } self.locationData = [[NSMutableArray alloc] init]; NSData *recievedData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@&#8221;http:\/\/htmlwin001.******.net\/blutalkasp\/locations2.asp?uid=%@&amp;von=%d&amp;bis=%d&#8221;, [[UIDevice currentDevice] uniqueIdentifier], von, bis]]]; NSString *recievedString = [[NSString alloc] initWithData:recievedData encoding:NSUTF8StringEncoding]; SBJsonParser *json = [[SBJsonParser alloc] init]; NSMutableDictionary *jsonData [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4062","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4062","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4062"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4062\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}