MyPlatesViewController* viewController = [[MyPlatesViewController alloc] initWithNibName:@"MyPlates" bundle:nil ];
[self.view addSubview:viewController.view];
then i delete my viewController
[self.view removeFromSuperview];
but leak instrument shows 20 MB memory
What is wrong ?
You called
alloc
so it's your responsibility to release it. Your code should look like this:Note that your controller is retained by the view when you call addSubview and released when you call removeFromSuperview. So with your current code the retain count of viewController is still 1 after calling removeFromSuperview.
Additionally you should review objective-c memory manament here: http://developer.apple.com/library/mac/#documentation/cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html
You leaked the view controller object. After you remove the view from its superview, you need to release the controller as well.
Alternatively, you can do the following:
Then, when
dismissModalViewController
is called, both the view and the view controller will be released properly.