I'm trying to present a custom view controller, with custom views loaded from detached NIBs, modally using the presentModalViewController message.
The process开发者_运维技巧 works fine but I noticed (using the allocations instruments) that every time the view controller is presented modally (or by a nav controller push) the memory is not being reclaimed once dismissed. What ends up happening is that if the user activates the modal view controller several times eventually the application will receive a memory warning and eventually crash.
I'm trying to find a way to force-release the memory allocated for the modal view controller. At this point, i've gone as far as to create a single instance of the view controller owned by the parent view controller and re-use the view controller for all modal invocations.
Any help with regards to releasing dismissed modal view controllers would be greatly appreciated.
Thanks guys!
After you call presentModalViewController:animated:
, you can release the presented view controller if you have no further need for it. UIKit will itself retain it as long as it is presented.
Check out object ownership. Your view controller is responsible for presenting the modal view controller so it retains ownership of it. Thus, you can release the controller after you instantiate it and present it using presentModalViewController:animated.
精彩评论