首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Iphone >

【iPhone】字符串泄露有关问题

2013-01-23 
【iPhone】字符串泄露问题在程序中有下述代码片段,我想问问,1.这个strURL会不会产生内存泄露?2.如果泄露了,

【iPhone】字符串泄露问题
在程序中有下述代码片段,我想问问,
    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?字符串?内存泄露?崩溃
[解决办法]
只要你不 用 retain,copy等使得 NSObject 计数器+1.并且 string 用系统的方法,一般系统都会自动回收的。

系统的方法 类似于 [NSstring alloc] init] autorelease]

在你写的这段代码里面, 不存在内存泄漏的问题。不过 有点需要注一下[[commonManager getHostStr]若为null,有可能crash

热点排行