简体   繁体   中英

LoadXMLByUrl: Method returns an Objective-C object with a +1 retain count

@synthesize xmlcont;

And

- (void)viewDidLoad {
/* Line 35 */ xmlcont =[[pxmlC alloc]loadXMLByUrl:@"http://openmenu.com/api/v1/restaurant?key=57d3661c-0fa1-11e1-80ac-00163eeae34c&name=rusc"];
for (pxml *t in [xmlcont xmlArray]) {
    NSLog(@"Name: %@ %d",[t rname],[[xmlcont xmlArray] indexOfObject:t] );
}
NSLog(@"abc");
[super viewDidLoad];}

And

- (void)dealloc {
    [xmlcont release];
    [super dealloc];
}

But Build ans Analyze said :

Potential leak of an object allocated on line 35

When I click ">", it said:

Method returns an Objective-C object with a +1 retain count (owning reference)

Object allocated on line 35 is no longer referenced after this point and has a retain count of +1 (object leaked)

Like this: http://www.freeimagehosting.net/newuploads/af6b3.png

I can't understand... Please help me fix it. Thank you so much ^^

If your property is declared as retain you should set it via the accessor and autorelease

self.xmlcont = [[[pxmlC alloc] loadXMLByUrl:@"http://openmenu.com/api/v1/restaurant?key=57d3661c-0fa1-11e1-80ac-00163eeae34c&name=rusc"] autorelease];

also you should follow naming conventions and have an init or init... initializer. If there is one you should call init bebore calling loadXMLByUrl .

I think that the analyzer is confused by the ill-named initializer. Initializer names have to start with init… , so that the analyzer knows the method will return the receiver. Rename your loadXMLByUrl initializer to initWithContentsOfURL and see if that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM