简体   繁体   中英

Memory Leak in Dismissing Modal View Controller

In controller named controller1, I am pushing a modal view controller

     AddConversationViewController *addController = [[AddConversationViewController alloc] 
 initWithNibName:@"AddConversationViewController" bundle:nil];
 //addController.delegate = self;    
 UINavigationController *navigationController = [[UINavigationController alloc]
 initWithRootViewController:addController];
 [self presentModalViewController:navigationController animated:YES];
 [addController release];
 [navigationController release];

and then in that addcontroller, I have allocated several object. but in the dealloc method, when i release those objects, I will get BAD_ACCESS warning when i dismiss the modal view controller. If I don't release those objects I have allocated, it doesn't give the BAD_ACCESS warning. those objects I have allocated before are not released nor retained.

Does anybody know how to fix this memory leak?

Using Xcode 3.2 you can use the Clang Static Analyzer to see exactly where your memory management is going wrong. Simply choose "Build and Analyze" from the Build menu to use the tool.

I can only guess that when you dismiss the addController, you didn't deallocate the addController yet but you deallocate its objects.

So, can you try to put deallocate code into dealloc method of the addController

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM