开发者

Iphone memory leak

The following code snippet is from facebook.m file:

-(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];
}
开发者_开发技巧

I have found a 100% memory leak in fullURL initialization line. I can't found solution for it..

If any one know solution for it then please help me.


There is not a leak here. The stringByAppendingString: method returns a new string which is already added to the autorelease pool.


Instruments finds the leak. It disappears if you get rid of the retain in the FBRequest class method

+ (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;
}

But here all seems to be ok for me, so I can't say if the bug is here or in Instruments. Suggestions?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜