Objective-c MRC multiple objects referencing each other in memory management

Source: Internet
Author: User

In the MRC environment, assuming that the Ctroom object is a member variable of Ctperson, it should be noted that the code is as follows when modifying the Ctroom object:

-(void) Setroom: (Ctroom *) room{
It is necessary to determine whether the new and old values are equal and, once equal, [_room release] is equivalent to [window release], then [retain] throws an exception. if (_room! = ) { [_room release]; Release old value = [retain]; Retain new value }}

-(void) Dealloc

{

[_room release];

_room = nil;

self. Bedroom = nil;//At the same time, this sentence code is equivalent to the previous two sentences

[Super Dealloc];]

}

    Ctperson *person = [[Ctperson alloc] init];     *r = [[Ctroom alloc] init];    [Person Setroom:r];    [R Release];     = R;    [Person release];    

Objective-c MRC multiple objects referencing each other in memory management

Related Article

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.