I declared a Global Object:
YViewController * yViewController
When in App Launch I am calling:
[self methodOne];
The method does this:
-(void)methodOne
{
yViewController = [[YViewController alloc] initWithNibName:@"YViewController" bundle:nil];
self.window.rootViewController=yViewController;
}
When a button clicked in YViewController I am calling:
[self methodTwo];
The method does this:
-(void)methodTwo
{
XViewController * xViewController = [[XViewController alloc] initWithImage:myImage];
self.window.rootViewController=xViewController;
}
When a back button tapped on XViewController I am calling [self methodOne]; which navigates back to the YViewController.
The issue is, while I am using ARC, I could not flush/release the xViewController object. Also when checking on instruments,
the memory of XViewController keep on increasing as I tap back and forth between XViewController and YViewController.
How can I manage memory in this type of situations with ARC?
If the source of XViewController is open, I would have tweaked it to go with navigation. Any ways ..
Okay so, basically you are creating a new object of ViewController every time, and that is what is resulting in the pile of the memory.
You should have ‘XViewController * xViewController’ and ‘YViewController * yViewController’ as class variables and your methods should be some thing like this eg.
Look if the object exists, and if it does, don’t allocate it again.