|
Category: iOS memory management |
The role of Nil and release:
Nil is to set the pointer of an object to null, just cut off the pointer to the object in memory, and release is the real notification of memory release this object, but in iOS does not immediately release memory, but the memory counter cut off 1, until the counter becomes 0, will release memory So the purpose of release is to free up memory, and Self.object = nil, is to empty the pointer.
So nil does not release memory, only release to really free memory.
The order in which they are used:
If it is nil without release, then it is tantamount to making a memory leak because nil after release has no effect.
Conversely, if the interface object is used only if release is not set self.myoutlet = nil, then the program may not error, but it will be very unstable, not robust, prone to crashes.
Since an interface object has been released after release, the memory allocated to it has been freed, and the program will be crash if the object is re-used after the release.
If you set the pointer to empty after releasing it, it will not crash even if the object is used by the subsequent program.
This article is from the Linux commune website (www.linuxidc.com) Source Link: http://www.linuxidc.com/Linux/2012-06/62035.htm
Strong similar to retain
Weak similar to assign
The difference between the iOS memory nil and release