We've integrated facebook into an application to upload photos. This has been working great but recently using the XCode Alloc tool to track down any memory leaks we've discovered what seems to be an awful one. We are running an upload process in a separate dispatch thread. Then we're loading our facebook upload method in an auto release pool. When the upload gets called, the image goes on it's way to the appropriate FB profile. But, while uploading an NSKeyValueMethodForPattern gets created and holds about 500KB. Then, the big one, -[NSConcreteMutableData appendBytes:length] get's created and consumes about 4.5MB depending upon the image size. These two are created for each uploaded image and NEVER RELEASED! I'm at a loss with this. The alloc tool points to the below as the culprit
- (FBRequest*)openUrl:(NSString *)url params:(NSMutableDictionary *)params
httpMethod:(NSString *)httpMethod delegate:(id<FBRequestDelegate>)delegate
{
[params setValue:@"json" forKey:@"format"];
[params setValue:kSDK forKey:@"sdk"];
[params setValue:kSDKVersion forKey:@"sdk_version"];
if ([self isSessionValid]) {
[params setValue:self.accessToken forKey:@"access_token"];
}
[_request release];
_request = [[FBRequest getRequestWithParams:params
httpMethod:httpMethod
delegate:delegate
requestURL:url] retain];
[_request connect]; // <<<< SAYING THIS IS 100% cause
return _request;
}
Here is the code we're using to create the thread and "release" pool to process and upload the image.
backgroundQueue = dispatch_queue_create("com.somecomp.appnameo.bgqueue", NULL);
dispatch_async(backgroundQueue, ^(void) {
NSAutoreleasePool *loopPool = [[NSAutoreleasePool alloc] init];
NSData *imageNSData = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", docDir, self.fileName]];
UIImage *img = [[UIImage alloc] initWithData:imageNSData];
fbResponse = 0;
//[facebook requestWithGraphPath:@"me" andDelegate:self];
[[delegate facebook] requestWithGraphPath:@"me/permissions" andDelegate:self];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
//@"Sent From Some APP!", @"name",
self.postTitle, @"caption",
// string, @"description",
img, @"picture",
//@"my photo's caption text here.", @"message",
nil];
[img release];
[[delegate facebook] requestWithMethodName:@"photos.upload"
andParams:params
andHttpMethod:@"POST"
andDelegate:self];
[loopPool drain];
});
Is there anything else I can do to release these mem hogs? I'm not a novice at this stuff but I'm at a loss with this. Any help here would be fantastic!
Thank you! - Jim