I have a problem with HEAP GROWTH and PERSISTENT elements seen in “Instruments Allocations” when I add a subview and I return to parent. The subview is a simple blank view with a back button added by IB.
In Instruments I see this when I repeat for 6 times the same action using “Mark heap”. The cicle is: click on button in parent to add Subview and going back to parent clickng back button in subview:

I think it would be zero! Is a very simple action.
The code that I use to load the subview in View1Controller.m is:
View2Controller *jv;
jv = [[View2Controller alloc] initWithNibName:nil bundle:nil];
[self.view addSubview:jv.view];
And in View2Controller.m I go back
-(IBAction) Back {
[self.view removeFromSuperview];
self.view = nil;
}
What am I doing wrong?
Thanks in advance.
When you use
[self.view removeFromSuperview];theself.viewis unlinked from its superview but it’s not released. So the memory footprint grows.In order to avoid the memory leaks you should release the memory by calling the
releasemethod on View2Controller instance created into your View1Controller.m file.For example, you can memorize the reference to the View2Controller instance created by setting a property (jv property in this example):
The
jvproperty should be defined with declaration properties as follow: