在程序中有下述代码片段,我想问问,
    1.这个strURL会不会产生内存泄露?
    2.如果泄露了,有没有可能导致程序立即崩溃
- (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];
}iPhone 字符串 内存泄露 崩溃

解决方案 »

  1.   

    只要你不 用 retain,copy等使得 NSObject 计数器+1.并且 string 用系统的方法,一般系统都会自动回收的。系统的方法 类似于 [NSstring alloc] init] autorelease]在你写的这段代码里面, 不存在内存泄漏的问题。不过 有点需要注一下[[commonManager getHostStr]若为null,有可能crash