Question : Memory Leak in Poping Modal View Controller

In controller named controller1, I am pushing a modal view controller
1:
2:
3:
4:
5:
6:
7:
8:
	 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?

Answer : Memory Leak in Poping Modal View Controller

The BAD_ACCESS error means that you are releasing an object that another function is currently using.  Run your code like this:

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

This adds some console messages before you release each of your objects.  If you see After addController released in your console, you know that [addController release]; is not causing your crash.  If you see both of those console messages, you know that none of those statements are causing a crash, but most likely, one of those 2 release statements is causing the crash.  I am thinking that the [navigationController release]; statement is causing your crash because you need that to move views via your navigationController.  If you remove that line, you shouldn't crash.  Removing addController shouldn't cause a crash because you just made that to move the view and it doesn't do anything else.  If you have any further questions, please feel free to ask me about them.
Random Solutions  
 
programming4us programming4us