How to implement didReceiveMemoryWarning?

前端 未结 6 1870
一生所求
一生所求 2020-11-30 19:38

I have developed a simple location aware iPhone application which is functionally working very well to our expectations except in the low memory condition of the phone .

6条回答
  •  萌比男神i
    2020-11-30 20:10

    One example i am posting...which i have copied from somwhere... it might give you some idea...

    - (void)didReceiveMemoryWarning {
    
        // Release anything that's not essential, such as cached data (meaning
        // instance variables, and what else...?)
    
        // Obviously can't access local variables such as defined in method
        // loadView, so can't release them here We can set some instance variables
        // as nil, rather than call the release method on them, if we have defined
        // setters that retain nil and release their old values (such as through use
        // of @synthesize). This can be a better approach than using the release
        // method, because this prevents a variable from pointing to random remnant
        // data.  Note in contrast, that setting a variable directly (using "=" and
        // not using the setter), would result in a memory leak.
        self.myStringB = nil;
        self.myStringD = nil;
        [myStringA release];// No setter defined - must release it this way
        [myStringC release];// No setter defined - must release it this way
    
        /* 3. MUST CONFIRM: NOT necessary to release outlets here - See override of
           setView instead.
        self.labelA = nil;
        self.imageViewA = nil;
        self.subViewA = nil;
         */
        // Releases the view if it doesn't have a superview
        [super didReceiveMemoryWarning];
    }
    

提交回复
热议问题