Detailed analysis of IOS development study notes

Source: Internet
Author: User

IOS developmentThe study notes case analysis is the content to be introduced in this article.ViewDidUnloadUsage andIOS 5Memory Management example content, see the details.

ViewDidUnload usage

This method is called when the system memory is tight. Note: viewController is not dealloc)

When the memory is tight, didreceivemorywarning before iPhone OS 3.0 is the only way to release useless memory, but the viewDidUnload method is better in OS 3.0 and later versions.

In this method, all IBOutlet, whether it is property or instance variable) has been set to the nil system release view and its release has been dropped)

Release other view-related objects, other objects created at runtime but not required by the system, and objects created in viewDidLoad.

After the release object is set to nilIBOutlet, you only need to set the object to nil. The release view has been released by the system)

ViewDidUnload is generally considered as the image of viewDidLoad, because when the view is requested again, viewDidLoad will be re-executed

Objects release in viewDidUnload must be easily re-created objects, such as objects created in viewDidLoad or other methods. Do not release user data or other objects that are hard to be re-created.

IOS 5 memory management example
 
IOS5 uses the Objective-C Automatic Reference Counting mechanism. In programming, we do not need to take the initiative to retain/release/autorelease an object.

In dealloc of MyClass

 
 
  1. NSLog(@"%s %d", __FUNCTION__, __LINE__); 

Perform the following operations in AppDelegateDidFinishLaunching:

 
 
  1. NSLog (@ "before 1 ");
  2. {
  3. Static MyClass * m = nil;
  4. M = [[MyClass alloc] init]; // m is not destroyed, and the object to which it is directed is not destroyed.
  5. }
  6. NSLog (@ "after 1 ");
  7. NSLog (@ "before 2 ");
  8. {
  9. MyClass * m = nil;
  10. M = [[MyClass alloc] init]; // m is destroyed, and the object is also destroyed.
  11. }

Print result:

 
 
  1. 2011-07-10 00:59:44.556 aaaaa[4965:207] before   
  2. 2011-07-10 00:59:44.558 aaaaa[4965:207] after   
  3. 2011-07-10 00:59:44.558 aaaaa[4965:207] before   
  4. 2011-07-10 00:59:44.558 aaaaa[4965:207] -[MyClass dealloc] 25  
  5. 2011-07-10 00:59:44.559 aaaaa[4965:207] after  

Summary:IOS developmentThe content of the Case Analysis of study notes has been introduced. I hope this article will help you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.