开发者

how to know when to release string for iphone

i have this

 NSXMLParser *xmlParserf = [[NSXMLParser alloc] initWithContentsOfURL:url];
    //  NSLog(@"URL%@",urlf);
    //Initialize the delegate.

    XMLParser *parserf = [[XMLParser alloc] initXMLParser];
    [xmlParserf setDelegate:parserf];

    //Start parsing the XML file.

    BOOL successs = [xmlParserf parse];

    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

    NSLog(@" this xml  is %d",[xmlParserf retainCount]);// getting error
    NSLog(@" this paaat is %d",[parserf retainCount]);// getting error

    if(successs)
    {
        NSLog(@"ZONE IS PARSED");
        [UIApplication s开发者_如何转开发haredApplication].networkActivityIndicatorVisible = NO;
    }
    else
    {
        NSLog(@"NOT PARSED!!!");
    }

    //[xmlParserf release]; not working
            //[parserf release];

now i dont know when to release those objects these are running in some threads


everytime you alloc (or copy), you must either release or autorelease.

In this case:

NSXMLParser *xmlParserf = [[[NSXMLParser alloc] initWithContentsOfURL:url] autorelease];

and

XMLParser *parserf = [[[XMLParser alloc] initXMLParser] autorelease];

It means that you keep it in memory at least until the end of the current function. If other objects hang on to it (i.e. retain it) then the objects stay in memory, until they are released (by those other objects).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜