IOS wild pointer and null pointer

Source: Internet
Author: User

A pointer that does not store any memory address is called a null pointer (a null pointer)

The wild pointer is a pointer to "junk" memory (memory not available). The wild hands are very dangerous.

For example, a class that defines a person, the person class has a-(void) SetName method

Person * per = [[Person alloc]init];

[Per SetName]; The meaning of this sentence is to send a setname message to the person object to which per is directed

[per release]; This code means sending a release message to the person object that the person is pointing to, and the person object will be destroyed when it receives the release message and the memory will be recycled

[per SetName]; This code will have a wild pointer error, the person object has been destroyed, the memory occupied by the person is already garbage memory, if you have access to this memory, it will report the wild pointer error. This memory is no longer available, it is not yours, and you have to visit it, it is certainly not legal.

per = nil; The code is to empty the per pointer and become a NULL pointer

[per SetName]; At this point the code is not error-free, but it cannot be executed because per is a null pointer. So the SetName method is not to be called.

IOS wild pointer and null pointer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.