Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When set objects to nil when using ARC?

I'm on an iPhone project using ARC. The application is a navigation based one, using UINavigationController.

The typical use case is to go from a "main" UIViewController to a "secondary" UIViewController multiple times, maybe up to 100 times. The secondary controller has a lot of static, local PNG images, some of them repeated.

I'm profiling the application and I can see how, when going from "main" to "secondary" controller, it allocates about 0.8 MB, but, when pressing the back button, it does not free the memory. So, when I go again to the secondary controller, other 0.8 MB are allocated, and so on...

Debugging, I noticed that viewDidUnload: method of the secondary UIViewController is never being called, but I also read that it's that method where I'm supposed to set to nil the references kept by the controller. Doing so in viewDidDisappear: does not help, because I want that to occur only when pressing the back button, that is, when popping the controller from the stack (the viewDidDisappear: method would be also called when pushing another controller on the stack).

So the questions are: is there where I have to do that? Can I force that method to be called? Is that behavior OK (profiling, the allocations went up to 20MB after some cycles of "main" -> "secondary" -> "main" -> "secondary" -> ...) ??

Thank you all in advance

like image 880
sonxurxo Avatar asked May 22 '12 09:05

sonxurxo


1 Answers

ARC is just used to reduce the code and manage the memory internally. For more details please go through the tutorial below so that you are able to understand the concepts more easily.

Understanding Automatic Reference Counting in Objective-C

I hope this might help you out.

like image 56
Akhilesh Sharma Avatar answered Sep 22 '22 18:09

Akhilesh Sharma