Discussion Forums  >  Uncategorized

Replies: 7    Views: 885

iMacintosh
I hate code!
Profile
Posts: 3
Reg: Aug 30, 2011
Dublin
30
09/07/11 02:38 PM (14 years ago)

Help Xcode finding MEMORY LEAKS when analyzing App

Hi everyone. I ran Analyze in Xcode and it came back with 124 memory leaks! I tried to fix them to no avail. I know nothing about code. Here's and example//show finish screen -(void)showFinishScreen{ [BT_debugger showIt:self:[NSString stringWithFormat:@showFinishScreen %@, @]]; //appDelegate irishaircorps1_appDelegate *appDelegate = (irishaircorps1_appDelegate *)[[UIApplication sharedApplication] delegate]; //get possible itemId of the screen to load NSString *loadScreenItemId = [BT_strings getJsonPropertyValue:screenData.jsonVars:@quizFinishScreenItemId:@]; //get possible nickname of the screen to load NSString *loadScreenNickname = [BT_strings getJsonPropertyValue:screenData.jsonVars:@quizFinishScreenNickname:@]; //bail if load screen = none if([loadScreenItemId isEqualToString:@none]){ return; } //check for loadScreenWithItemId THEN loadScreenWithNickname THEN loadScreenObject BT_item *screenObjectToLoad = nil; if([loadScreenItemId length] > 1){ screenObjectToLoad = [appDelegate.rootApp getScreenDataByItemId:loadScreenItemId]; }else{ if([loadScreenNickname length] > 1){ screenObjectToLoad = [appDelegate.rootApp getScreenDataByNickname:loadScreenNickname]; }else{ if([screenData.jsonVars objectForKey:@quizFinishScreenObject]){ screenObjectToLoad = [[BT_item alloc] init]; [screenObjectToLoad setItemId:[[screenData.jsonVars objectForKey:@quizFinishScreenObject] objectForKey:@itemId]]; [screenObjectToLoad setItemNickname:[[screenData.jsonVars objectForKey:@quizFinishScreenObject] objectForKey:@itemNickname]]; [screenObjectToLoad setItemType:[[screenData.jsonVars objectForKey:@quizFinishScreenObject] objectForKey:@itemType]]; [screenObjectToLoad setJsonVars:[screenData.jsonVars objectForKey:@quizFinishScreenObject]]; } } } //load next screen if it's not nil if(screenObjectToLoad != nil){ //build a temp menu-item to pass to screen load method. We need this because the transition type is in the menu-item BT_item *tmpMenuItem = [[BT_item alloc] init]; //build an NSDictionary of values for the jsonVars property NSDictionary *tmpDictionary = [NSDictionary dictionaryWithObjectsAndKeys: @unused, @itemId, [self.screenData.jsonVars objectForKey:@quizFinishScreenTransitionType], @transitionType, nil]; [tmpMenuItem setJsonVars:tmpDictionary]; [tmpMenuItem setItemId:@0]; //load the next screen [BT_viewControllerManager handleTapToLoadScreen:[self screenData]:tmpMenuItem:screenObjectToLoad]; [tmpMenuItem release]; }else{ //show debug [BT_debugger showIt:self:[NSString stringWithFormat:@%@,NSLocalizedString(@menuTapError,@The application doesn't know how to handle this action?)]]; } The app runs ok in Simulator. I want to release this App in The App store will Apple let It with these leaks? Thank you Maurice
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/08/11 10:13 AM (14 years ago)
Hi Maurice: Cool post. First, we are all very interested in finding / fixing / improving. I can say that literally tens of thousands of these are 'out there' and this is the first post like this. Occassionally we here of ways to improve it but have never heard '124 memory leaks found' So, I guess my question is what makes you think there are 124 memory leaks? I'm not trying to sound like an ass but instead trying to balance you suggesting that you don't 'know anything about code' but have somehow figured out a way to identify 124 memory leaks? One thing to keep in mind is the way Instruments works and how it show you memory allocations and other detailed feedback. It's very very confusing. In fact, it's beyond most of us to even understand what it's telling us! Funny. I'm for sure NOT an Instruments pro. So, of course we're happy to learn of memory leaks but doubt very much that there are 124 of them and don't even know where to begin looking without more details. The 'showFinishScreen' method you posted is not the problem - guaranteed ;-)
 
iMacintosh
I hate code!
Profile
Posts: 3
Reg: Aug 30, 2011
Dublin
30
like
09/08/11 10:35 AM (14 years ago)
Thanks David for the speedy response. I ran 'Analyze' in Xcode 4.1 [os x Lion] and it said I have 124 leaks. I didn't know anything was wrong with the app as it is working on the simulator perfect so far. It's just Xcode Analyze thats finding problems. The code 'showFinishScreen' was 1 example of a leak. The following code has 6 'potential leaks' //init application -(id)init{ if((self = [super init])){ [BT_debugger showIt:self:[NSString stringWithFormat:@initializing buzztouch application %@, @]]; //init variables. self.jsonVars = nil; self.rootNavController = nil; self.rootTabBarController = nil; self.rootTheme = nil; self.rootDevice = nil; self.rootUser = nil; self.rootNetworkState = nil; self.rootLocationManager = nil; self.currentItemUpload = nil; self.tabs = [[NSMutableArray alloc] init]; self.screens = [[NSMutableArray alloc] init]; self.themes = [[NSMutableArray alloc] init]; //initialize the rootDevice to store information associated with this device self.rootDevice = [[BT_device alloc] init]; //initialized the rootUser to store information associated with the user (may or may not be logged in) self.rootUser = [[BT_user alloc] init]; //initialized the rootNetworkState to track network state changes self.rootNetworkState = [[BT_networkState alloc] init]; } return self; } I hope this finds & helps others in the same boat Thanks again David
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/08/11 10:38 AM (14 years ago)
Cool, maybe you're onto something? Do this (it will be very helpful for lots of folks)... a) Fire up your analyzer... b) Grab some screen shots of 'all you can' The more the better ;-) c) Zip them up and send them to info 'at' buzztouch.com Tip: On you mac, hold Shift + Command then press the number 4 to get get a cool little cross-hair to drag / select then take a screen shot. The screenshot you grab will be saved on your desktop.
 
iMacintosh
I hate code!
Profile
Posts: 3
Reg: Aug 30, 2011
Dublin
30
like
09/08/11 11:02 AM (14 years ago)
Sent some screen shots of the above Thanks again David Maurice
 
GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
like
09/09/11 12:13 AM (14 years ago)
Hey David...Ran Analyzer against one of my apps just to see what happens..got several possible leaks as well. I'll email you the file. No idea if this is real stuff or just Xcode being picky. Thanks!
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/10/11 10:19 AM (14 years ago)
@iMacintosh, @GoNorthWest. Tough few days around here with lots going on (USA Today, are you kidding me!). Anyway, I'll get to the memory thing and report back as soon as I can. Thanks for the emails ;-)
 
shockme66
Apple Fan
Profile
Posts: 81
Reg: Sep 12, 2011
Easton PA
1,010
like
09/13/11 07:31 PM (14 years ago)
I am seeing 58 memory leaks on my app using v1.5 is this normal? Any solutions or tips? Leaked Object Address Size Responsible Library Responsible Frame SBJsonParser,0x2e1a70 32 Bytes cigarsmoker -[BT_application validateApplicationData:] SBJsonParser,0x2baa80 32 Bytes cigarsmoker -[cigarsmoker_appDelegate loadAppData] SBJsonParser,0x2baa80 32 Bytes cigarsmoker -[cigarsmoker_appDelegate loadAppData] BT_item,0x2b5bb0 48 Bytes cigarsmoker -[BT_screen_menuList loadData] __NSArrayM,0x2ade70 32 Bytes cigarsmoker -[BT_application init] __NSArrayM,0x2ade70 32 Bytes cigarsmoker -[BT_application init] __NSArrayM,0x2a9470 32 Bytes cigarsmoker -[BT_application init] __NSArrayM,0x2a9470 32 Bytes cigarsmoker -[BT_application init] __NSArrayM,0x2a9470 32 Bytes cigarsmoker -[BT_application init] __NSArrayM,0x2a9470 32 Bytes cigarsmoker -[BT_application init] __NSArrayM,0x27ee50 32 Bytes cigarsmoker -[BT_application init] __NSArrayM,0x27ee50 32 Bytes cigarsmoker -[BT_application init] __NSArrayM,0x27ee50 32 Bytes cigarsmoker -[BT_application init] SBJsonParser,0x2766e0 32 Bytes cigarsmoker -[BT_application parseJSONData:] SBJsonParser,0x2766e0 32 Bytes cigarsmoker -[BT_application parseJSONData:] SBJsonParser,0x2766e0 32 Bytes cigarsmoker -[BT_application parseJSONData:] SBJsonParser,0x2766e0 32 Bytes cigarsmoker -[BT_application parseJSONData:] SBJsonParser,0x274f60 32 Bytes cigarsmoker -[cigarsmoker_appDelegate connectionDidFinishLoading:] SBJsonParser,0x274f60 32 Bytes cigarsmoker -[cigarsmoker_appDelegate connectionDidFinishLoading:] SBJsonParser,0x26c7a0 32 Bytes cigarsmoker -[cigarsmoker_appDelegate connectionDidFinishLoading:] SBJsonParser,0x26c7a0 32 Bytes cigarsmoker -[cigarsmoker_appDelegate connectionDidFinishLoading:] SBJsonParser,0x266fd0 32 Bytes cigarsmoker -[cigarsmoker_appDelegate connectionDidFinishLoading:] SBJsonParser,0x266fd0 32 Bytes cigarsmoker -[cigarsmoker_appDelegate connectionDidFinishLoading:] SBJsonParser,0x25ddb0 32 Bytes cigarsmoker -[cigarsmoker_appDelegate connectionDidFinishLoading:] SBJsonParser,0x25ddb0 32 Bytes cigarsmoker -[cigarsmoker_appDelegate connectionDidFinishLoading:] SBJsonParser,0x25ddb0 32 Bytes cigarsmoker -[cigarsmoker_appDelegate connectionDidFinishLoading:] GeneralBlock-64,0x25bbb0 64 Bytes cigarsmoker -[BT_screen_menuButtons layoutScreen] GeneralBlock-64,0x25bbb0 64 Bytes cigarsmoker -[BT_screen_menuButtons layoutScreen] UIDeviceRGBColor,0x253cc0 32 Bytes UIKit +[UIColor allocWithZone:] UIDeviceRGBColor,0x2503f0 32 Bytes UIKit +[UIColor allocWithZone:] UIDeviceRGBColor,0x2503f0 32 Bytes UIKit +[UIColor allocWithZone:] __NSArrayM,0x24e960 32 Bytes cigarsmoker -[BT_screen_menuList loadData] __NSArrayM,0x24e960 32 Bytes cigarsmoker -[BT_screen_menuList loadData] GeneralBlock-16,0x24b520 16 Bytes cigarsmoker -[BT_screen_images viewDidLoad] NSPathStore2,0x24b500 32 Bytes Foundation +[NSPathStore2 pathStoreWithCharacters:length:] __NSArrayM,0x24af90 32 Bytes cigarsmoker -[BT_screen_images viewDidLoad] BT_item,0x2400d0 48 Bytes cigarsmoker -[BT_screen_menuList loadData] BT_item,0x2400d0 48 Bytes cigarsmoker -[BT_screen_menuList loadData] BT_item,0x23e390 48 Bytes cigarsmoker -[BT_screen_menuList loadData] NSConcreteMutableData,0x239640 32 Bytes Foundation +[NSMutableData(NSMutableData) allocWithZone:] NSConcreteMutableData,0x239640 32 Bytes Foundation +[NSMutableData(NSMutableData) allocWithZone:] GeneralBlock-16,0x239630 16 Bytes Foundation -[NSConcreteMutableData initWithCapacity:] GeneralBlock-16,0x239630 16 Bytes Foundation -[NSConcreteMutableData initWithCapacity:] GeneralBlock-16,0x239630 16 Bytes Foundation -[NSConcreteMutableData initWithCapacity:] BT_item,0x238a40 48 Bytes cigarsmoker -[BT_screen_menuList loadData] BT_item,0x238a40 48 Bytes cigarsmoker -[BT_screen_menuList loadData] BT_item,0x238a40 48 Bytes cigarsmoker -[BT_screen_menuList loadData] CGColor,0x238520 48 Bytes CoreGraphics CGTypeCreateInstanceWithAllocator CGColor,0x238520 48 Bytes CoreGraphics CGTypeCreateInstanceWithAllocator CGColor,0x238520 48 Bytes CoreGraphics CGTypeCreateInstanceWithAllocator BT_item,0x237630 48 Bytes cigarsmoker -[BT_screen_menuList loadData] BT_item,0x237630 48 Bytes cigarsmoker -[BT_screen_menuList loadData] SBJsonParser,0x237550 32 Bytes cigarsmoker -[BT_screen_menuList parseScreenData:] BT_item,0x228800 48 Bytes cigarsmoker -[BT_screen_menuList loadData] BT_item,0x228800 48 Bytes cigarsmoker -[BT_screen_menuList loadData] GeneralBlock-16,0x2210c0 16 Bytes cigarsmoker -[BT_screen_imageEmail showOptions] __NSArrayM,0x219f60 32 Bytes cigarsmoker -[BT_rssParser setItemsToParse] GeneralBlock-16,0x2196b0 16 Bytes cigarsmoker -[BT_rssParser setItemsToParse]
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.