iPhone Development - Simulate Memory Warning -


Background :

I have a tab bar application in each tab Navigation Controller, which allows the user to move from one view to another, which is showing a drill information of the data (each view is controlled by a view controller and in each view controller category the DidReiveiveMemoryWarning method). The list is populated by dragging data from web services.

Problem :

When I use the "Hardware> Simulate Memory Warning" option of the iPhone Simulator, didReiveiveMemory Warning method Is called for all my controllers - even the user who is watching. I do not want to clear any content that is being used by Active View Controller. How can I achieve that?

After the release of data due to a memory alert, which method should be implemented to reload the data? (I see that the View controller class has a table view call viewDidLoad method, when the user returns to that view, but if in the view (called UIWebView) then viewDidLoad < / Code> Method

Edit (Friday 30 January 2009 - 03:10 pm)

(Note: I am using the interface to create an idea For Builder, and loadView method is commented.)

Therefore, when a view controller has a memory warning The following steps are taken:

Memoriaming [[Super Dadarsevim Memory Warning];

  • The result of calling [super didReiveiveMemoryWarning] , [self setView: nil ] Automatically becomes known?

  • If a resource needs to be cleaned, then setView method to clean local resources Should be overwritten.

  • [Self set view: zero] Not that the view is currently active (by default). right? - I'm really curious about which method it decides and how?

  • Can you please confirm besides this, I was getting an error after this approach, but the code of the controller class continued the dealloc Fixed the problem after adding myObject = nil . Thank you.

    This is an old question, but I can not find the correct answer, so here goes:

    When a memory alert is received, -didReceiveMemory Warning is called in all view controllers, whether it is "on" or not, the view controller is just listening to the memory warning event broadcast Are there.

    If the view controller's view is not being used at the time of memory warning, then the controller will unload it by setting the property to zero, how does it show that the scene is used? According to the view's -superview property, if view.superview is zero, the view is not part of any tree and it can be safely loaded.

    When this happens, the controller is called -viewDidUnload , it is the right place to unload any outlet, and anything that -viewDidLoad Has been rebuilt.


    then what is - for DDRECEMMemory warning ? Your controller contains objects that are not accessible. For example, you may have a controller that sometimes requires a large part of the data from the file, but not always you can have the asset set for it:

      - (NSDT *) BigChunkOfData {// Get data from our example variable_data, if read from disk if necessary (_data == zero) {_data = [[NSData alloc] initWithContentsOfFile: @ "/ path / to / data"]; } Return _data; }  

    This will first read data from the disk, then place it in a frequency variable. Since the _data variable is built on demand, since it is safe for us to load it in less memory conditions: this is the only time that we need it the next time.

      - (zero) done Tharaveemmori warning {[Super Demresewami Warning]; [_data release]; _data = zero; // & lt; - very important: do not leave strong references false)  

    Comments