Iphone内存泄漏

时间:2010-11-27 12:24:07

标签: iphone objective-c

以下代码段来自facebook.m文件:

-(void) requestWithMethodName:(NSString *)methodName 
                andParams:(NSMutableDictionary *)params 
            andHttpMethod:(NSString *)httpMethod 
              andDelegate:(id <FBRequestDelegate>)delegate {
    NSString * fullURL = [kRestApiURL stringByAppendingString:methodName];
    [self openUrl:fullURL params:params httpMethod:httpMethod delegate:delegate];
}

我在fullURL初始化行中发现了100%的内存泄漏。我无法找到它的解决方案..

如果有人知道解决方案,请帮助我。

2 个答案:

答案 0 :(得分:0)

这里没有泄漏。 stringByAppendingString:方法返回一个已添加到自动释放池的新字符串。

答案 1 :(得分:0)

仪器发现泄漏。如果你摆脱FBRequest类方法中的保留

,它就会消失
+ (FBRequest *)getRequestWithParams:(NSMutableDictionary *) params
                         httpMethod:(NSString *) httpMethod
                           delegate:(id<FBRequestDelegate>) delegate
                         requestURL:(NSString *) url {
  FBRequest* request    = [[[FBRequest alloc] init] autorelease];
    request.delegate      = [delegate retain]; 
    request.url           = [url retain];         // <----- no leak if you don't retain url
    request.httpMethod    = [httpMethod retain];
    request.params        = [params retain];
  request.connection    = nil;
  request.responseText  = nil;

  return request;
}

但是这里似乎对我来说都是好的,所以我不能说这个bug是在这里还是在仪器中。建议?