Thursday, September 26, 2013

[IPhone] string leaks

in the program with the following code snippet, I want to ask,
1 This strURL will not produce memory leaks?
2 If leaked, there may cause the program
crashes immediately ?


- (LSHTTPRequest *) request
{
NSString * strURL = [[commonManager getHostStr] stringByAppendingString: @ "/ cate.action? Act = getlist & type = id"];

if (_categoryID> 0)
{
strURL = [strURL stringByAppendingFormat: @ "& id =% d", _categoryID];
}
strURL = [self requestURLByAppendPageParams: strURL];
LSHTTPRequest * request = [[LSHTTPRequest alloc] initWithURL: [NSURL URLWithString: strURL]];
return [request autorelease];
}
Reply:
As long as you do not use retain, copy, etc. makes NSObject counter +1 and string in a systematic way, the general system will automatically be recycled.

Systematic approach is similar to [NSstring alloc] init] autorelease]

In this code you write inside, there is no memory leak problem. But little need to note about [[commonManager getHostStr] if is null, there may crash

No comments:

Post a Comment