现在的位置: 首页 > 综合 > 正文

官方ViewController programming guide 上面说的,在iOS6以后要这样干: Really?

2013年10月09日 ⁄ 综合 ⁄ 共 1437字 ⁄ 字号 评论关闭

官方ViewController programming guide 上面说的,在iOS6以后要这样干:


测试了下,确实可行!


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];

    // Add code to clean up any of your own resources that are no longer necessary.


    double version = [[UIDevice currentDevice].systemVersion doubleValue];//判定系统版本。

    if (version>=6.0f  &&  !self.view.window)
    {
        // Add code to preserve data stored in the views that might be

        // needed later.

       ( //尼玛,还能这么写!

        [self  viewDidUnLoad];

        self.view = nil;)



        self.XXX = nil;

    
        // Add code to clean up other strong references to the view in
        // the view hierarchy.
        self.view = nil;
    }

Memory Management

Memory is a critical resource in iOS, and view controllers provide built-in support for reducing their memory footprint at critical times. The UIViewController class
provides some automatic handling of low-memory conditions through itsdidReceiveMemoryWarning method,
which releases unneeded memory.

Prior to iOS 6, when a low-memory warning occurred, the UIViewController class purged its views if it knew it could reload or recreate them again
later. If this happens, it also calls the viewWillUnload and viewDidUnload methods
to give your code a chance to relinquish ownership of any objects that are associated with your view hierarchy, including objects loaded from the nib file, objects created in your viewDidLoad method,
and objects created lazily at runtime and added to the view hierarchy. On iOS 6, views are never purged and these methods are never called. If your view controller needs to perform specific tasks when memory is low, it should override the didReceiveMemoryWarning method.

抱歉!评论已关闭.