【发布时间】:2012-04-13 18:55:33
【问题描述】:
我们已将 facebook 集成到应用程序中以上传照片。这一直很好,但最近使用 XCode Alloc 工具来追踪我们发现的任何内存泄漏似乎很糟糕。我们正在一个单独的调度线程中运行一个上传过程。然后我们在自动发布池中加载我们的 facebook 上传方法。当上传被调用时,图像会继续发送到相应的 FB 配置文件。但是,在上传 NSKeyValueMethodForPattern 时,会创建并保存大约 500KB。然后,创建大的 -[NSConcreteMutableData appendBytes:length] 并根据图像大小消耗大约 4.5MB。这两个是为每个上传的图像创建的,永远不会发布!我对此感到茫然。 alloc工具指向下面是罪魁祸首
- (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;
}
这是我们用来创建线程和“释放”池以处理和上传图像的代码。
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];
});
我还能做些什么来释放这些内存猪吗?我不是这个东西的新手,但我对此感到茫然。这里的任何帮助都会很棒!
谢谢! - 吉姆
【问题讨论】:
-
您上次更新 FBConnect 代码是什么时候?看看github上那个方法,第167行:github.com/facebook/facebook-ios-sdk/blob/master/src/Facebook.m
-
我昨晚刚更新了代码,遇到了各种递归问题,来看看我更新到了递归错误。在失去 5 个小时的生命后,我再次更新。仍然有同样的问题。
标签: iphone objective-c xcode memory-leaks dispatch