0
@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 ^^

2 Answers 2

0

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.

3
0

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.

6
  • Thank you so much. But I have defined -(id)loadXMLByUrl:(NSString *)urlString in .h and .m files
    – Trinh
    Nov 24, 2011 at 15:01
  • You have to rename the method from loadXMLByUrl to initWithContentsOfURL, that should help.
    – zoul
    Nov 24, 2011 at 15:10
  • this is my (id)loadXML... [freeimagehosting.net/newuploads/c2fa2.png ] I have used initWithContentOfURL
    – Trinh
    Nov 24, 2011 at 15:34
  • We don’t understand each other. Your class has an initializer called loadXML. That’s a bad name, because it confuses the code analyzer. You have to rename the method to initWithContentsOfURL or anything else that starts with “init”.
    – zoul
    Nov 24, 2011 at 15:49
  • Look. If you want to get rid of the analyzer warning, try to rename the method. It’s all I can say.
    – zoul
    Nov 24, 2011 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.