The difference between nil Nil NULL in iOS

1. nil
When an object is set to nil, the memory address of the object will be reclaimed by the system. After emptying, any operations related to reference counting such as retain, copy, etc. cannot be performed.
2. Nil
nil is completely equivalent to Nil, but due to programming habits, people generally use nil for objects and Nil for classes.
3. NULL
is inherited from the C language and is a simple null pointer
4. [NSNull null]
is the key point: The difference between [NSNull null] and nil is that nil is an empty object, which has been completely removed from memory gone, and if we want to express the idea of ​​"we need to have such a container, but this container has nothing in it", we use [NSNull null], which is "an object whose value is null". If you check the development documentation you will find that the NSNull class inherits NSObject and has only one "+ (NSNull *) null;" class method. This means that the NSNull object has a valid memory address, so any reference to it in the program will not cause the program to crash.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325501447&siteId=291194637