There is no problem with this, it is crazy release. But today I found that the original simulator could simulate a situation where the memory is insufficient.ProgramSome errors have occurred, and I have learned more about the two.
Viewdidunload is executed only when the memory is insufficient and is executed on all non-currently displayed controllers. You can use the simulator to execute: hardware to Simulate Memory warnings. When executed When the controller of viewdidunload is re-displayed, it is re-executed. Viewdidload. For example, a push B triggers a memory warning (automatically executed by ). Viewdidunload ) Pop B (then a re-executes Viewdidload ). Dealloc is executed when the object is destroyed. For example:
A= [[A alloc]Init];
[A release];// At this time, a executesDealloc, but not executedViewdidunload
As you can see,Viewdidunload andThere is no sequential relationship between dealloc execution. Then you may have another question: InInside viewdidunload
Self.Outview=Nil;
Self.Loaddingicon=Nil;
InDealloc
[_ Outview release];
[_ Loaddingicon release];
For the differences between the two operations, see my previous note [iOS development Notes]: @ property and member variables.
Setting a pointer to nil is used to prevent the program from crash from accessing a released object, and sending a message to a null pointer will return 0 without triggering a crash.
Think about the example above.When viewdidunload is used, if only the Member is release, and when other places access the member, the program directly crash because the object of the address pointed to by the pointer has been release.
However, whenDealloc, there is no possibility of such a crash, so it is more efficient to disable nil.
Here, we should be able to understand what they should put.
As the Internet saysViewdidunloadYou can release something that is easy to re-build, such as local images.Viewdidload must be rebuilt.
For things that are not easy to re-build, such as re-download data from the server, it can be built in init,Do not release viewdidunload.