Author: failingProgramMember-eight gods
Memory Management plays a very important role in IOS program development. For a program with poor processing performance, crash occurs on the actual device.
For output ports that are often used with retain in the View Controller, be sure to release them in dealloc.
The attribute declared by obj-C has the following features: Assign the new object to the current attribute and automatically release the old object in the attribute.
-
- In appdelegate. if there is a window output port in m, or a navigation View Controller or another view controller is added, execute the release method of these output ports in the dealloc method. instead of executing release in applicationdidfinishlaunching.
- In a separate custom View Controller, if the didreceivememorywarning method is executed when a notification of memory shortage is received, it uninstalls the current view form and executes the viewdidunload method, therefore, the output port defined in the square view is set to nil in this method. at the same time, execute the corresponding output port release method in the dealloc method of the view (this method is executed when the release of the View Controller is called.
-(Void) Viewdidunload
{
Self.** =Nil;
}-(Void) Dealloc
{
[**Release];
[Supper dealloc];
}
-
- The release method is automatically maintained by the memory pool of the system.
- If I add alloc TO THE appdelegate. M file and init A View Controller, and then add it to it through the initwithrootviewcontroller method of the navigation controller, then release the View Controller after adding the controller. Example:Mycontroller=[[***Alloc] initwithnibname:"***"Bundle: Nil];
Uinavigationcontroller*Navi=[[Uinavigationcontroller alloc] initwithrootviewcontroller: mycontroller];
[Mycontroller release];
[Tabcontroller presentmodalviewcontroller: Navi animated: Yes];
[Navi release];
- The variables are declared in the Custom View Controller, but the corresponding attributes are not defined. In this case, the object release rules are the same as the 1st.@ Interface *** : Uiviewcontroller
{
Uiview * _ View;
}
@ End@ Implementation***
-(Void) Loadview
{
[Supper loadview];
_ View=[[Uiview alloc] initwithframe: [self. View bounds];
[Self. View addsubview: _ view];
}
-(Void) Dealloc
{
[_ View release];
[Supper dealloc];
}
@ End
- In the basic development tutorial of iPhone 3, switch Code I think there is a wrong sequence in it. I checked it on Google and many people asked the same question.@ Implementation switchviewcontroller
@ Synthesize blueviewcontroller;
@ Synthesize yellowviewcontroller;
- ( Void ) Viewdidload
{
Blueviewcontroller * Bluecontroller = [[Blueviewcontroller alloc] initwithnibname: @" Blueview " Bundle: Nil];
Self. blueviewcontroller = Bluecontroller;
[Self. View insertsubview: bluecontroller. View atindex: 0 ];
[Bluecontroller release];
}
- (Ibaction) switchviews :( ID) sender
{
[Uiview beginanimations: @ "view flip" context: Nil];
[Uiview setanimationduration: 1.25];
[Uiview setanimationcurve: uiviewanimationcurveeaseinout];
If (Self. yellowviewcontroller. View. superview = Nil) // this statement is the most interesting and the OBJ-C allows messages to nil.
{
If (Self. yellowviewcontroller = Nil)
{
Yellowviewcontroller * Yellowcontroller =
[[Yellowviewcontroller alloc] initwithnibname: @" Yellowview "
Bundle: Nil];
Self. yellowviewcontroller = Yellowcontroller;
[Yellowcontroller release];
}
[Uiview setanimationtransition: Uiviewanimationtransitionflipfromright Forview: Self. View cache: Yes];
[Blueviewcontroller viewwillappear: Yes];
[Yellowviewcontroller viewwilldisappear: Yes];
[Blueviewcontroller. View removefromsuperview];
[Self. View insertsubview: yellowviewcontroller. View atindex: 0 ];
[Yellowviewcontroller viewdiddisappear: Yes];
[Blueviewcontroller viewdidappear: Yes];
}
Else
{
If (Self. blueviewcontroller = Nil)
{
Blueviewcontroller * Bluecontroller =
[[Blueviewcontroller alloc] initwithnibname: @" Blueview "
Bundle: Nil];
Self. blueviewcontroller = Bluecontroller;
[Bluecontroller release];
}
// [Uiview setanimationtransition:
// Uiviewanimationtransitionflipfromleft
// Forview: Self. View cache: Yes];
// [Yellowviewcontroller viewwillappear: Yes];
// [Blueviewcontroller viewwilldisappear: Yes];
[Yellowviewcontroller. View removefromsuperview];
[Self. View insertsubview: blueviewcontroller. View atindex: 0 ];
// [Blueviewcontroller viewdiddisappear: Yes];
// [Yellowviewcontroller viewdidappear: Yes];
}
// [Uiview commitanimations];
}
-(Void) Didreceivememorywarning
{
[Super didreceivememorywarning];
If(Self. blueviewcontroller. View. superview=Nil)
Self. blueviewcontroller=Nil;
Else
Self. yellowviewcontroller=Nil;
}
-(Void) Dealloc
{
[Yellowviewcontroller release];
[Blueviewcontroller release];
[Super dealloc];
}
@ End
-
-
All are executed in dealloc. I have seen this in the WordPress iPhone client, but it seems that it is specially compatible with versions earlier than ios3. The viewdidunload method does not exist in versions earlier than 3.0, which is described in Apple's development manual.
-(Void) Dealloc
{
[Myview release], myview=Nil;
}Appendix.
Python/users/yangiori/downloads/facebook-three20-309d34e/src/scripts/ttmodule. py-P/users/yangiori/documents/iphoneliaobao. xcodeproj three20/case sensitive...