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
- NSLog(@"%s %d", __FUNCTION__, __LINE__);
Perform the following operations in AppDelegateDidFinishLaunching:
- NSLog (@ "before 1 ");
- {
- Static MyClass * m = nil;
- M = [[MyClass alloc] init]; // m is not destroyed, and the object to which it is directed is not destroyed.
- }
- NSLog (@ "after 1 ");
- NSLog (@ "before 2 ");
- {
- MyClass * m = nil;
- M = [[MyClass alloc] init]; // m is destroyed, and the object is also destroyed.
- }
Print result:
- 2011-07-10 00:59:44.556 aaaaa[4965:207] before
- 2011-07-10 00:59:44.558 aaaaa[4965:207] after
- 2011-07-10 00:59:44.558 aaaaa[4965:207] before
- 2011-07-10 00:59:44.558 aaaaa[4965:207] -[MyClass dealloc] 25
- 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!