Reprint: StackOverflow on iOS strong and weak image description

Source: Internet
Author: User

Http://stackoverflow.com/questions/9262535/explanation-of-strong-and-weak-storage-in-ios5

The difference is, an object would be deallocated as soon as there was no strong pointers to it. Even if weak pointers point-to-it, once the last strong pointer is gone, the object would be deallocated, and all remaining Weak pointers is zeroed out.

Perhaps an example was in order.

Imagine Our object is a dog, and that's the dog wants to run away (be deallocated).

Strong pointers is like a leash on the dog. As long as you had the leash attached to the dog, the dog would not run away. If Five people attach their leash to one dog, (five strong pointers to one object) and then the dog would not run away until a LL five leashes is detached.

Weak pointers, on the other hand, is like little kids pointing at the dog and saying "look! A dog! " As long as the dog is still on the leash, the little kids can still see the dog, and they ' ll still point to it. As soon as all the leashes is detached, though, the dog runs away no matter how many little kids is pointing to it.

As soon as the last strong pointer (leash) no longer points to an object, the object would be deallocated, and all weak poi Nters'll is zeroed out.

Reprint: StackOverflow on iOS strong and weak image description

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.