在几个viewController中跳转时,出现内存警告,并且navigationController的root UIviewController不显示了,是不是系统直接释放了controller的视图,当内存警告时要怎么手动释放不需要的资源,假如类中有一个@property数组,当内存警告时我在- (void)didReceiveMemoryWarning方法中释放掉,但在- (void)dealloc方法中还要释放吗?如果释放那不是重复释放了吗,如果不释放假如没有内存警告时不是有内存泄露吗,希望高手指点

解决方案 »

  1.   

    viewController出现内存警告时候,一般回把viewController中的view是否掉,viewController对象本身是存在的。一般只要把 viewDidload  喝viewDidUnload这两个函数写好就不会有问题。viewDidLoad
    Called after the controller’s view is loaded into memory.
    viewDidUnload
    Called when the controller’s view is released from memory.didReceiveMemoryWarning
    Sent to the view controller when the application receives a memory warning.- (void)didReceiveMemoryWarning
    Discussion
    The default implementation of this method checks to see if the view controller can safely release its view. This is possible if the view itself does not have a superview and can be reloaded either from a nib file or using a custom loadView method. If the view can be released, this method releases it and calls the viewDidUnload method.You can override this method (as needed) to release any additional memory used by your view controller. If you do, be sure to call the super implementation at some point to allow the view controller to release its view. In iOS 3.0 and later, if your view controller holds references to objects in the view hierarchy, you should release those references in the viewDidUnload method instead. In earlier versions of iOS, you should continue to release them from this method. See the discussion in the viewDidUnload method for information about how to safely release outlets and other objects.