我已经为iOS 8构建了一个应用程序,经过内存测试后发现了泄漏。
泄漏是相同的,并在我将文件上传到AWS存储库后重复。
泄漏按摩:
Leaked Object # Address Size Responsible Library Responsible Frame
_CFStreamDelegate 1 0x18914f30 32 Bytes CFNetwork HTTPNetConnection::transmitRequest(HTTPNetStreamInfo*, __CoreWriteStream*, CFStreamError*, unsigned char)
我找到了一个可以解决这个问题的功能:
// Amazone上传
-(void)uploadAWS{
NSString *fileName = DB_File;
NSString *directoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [directoryPath stringByAppendingPathComponent:fileName];
[self.transferManager cancelAll];
AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];
uploadRequest.body = [NSURL fileURLWithPath:filePath];
uploadRequest.key = UserName;
uploadRequest.bucket = BUCKET_NAME;
uploadRequest.contentType = @"application/x-sqlite3";
unsigned long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil] fileSize];
uploadRequest.contentLength = [NSNumber numberWithUnsignedLongLong:fileSize];
[[self.transferManager upload:uploadRequest] continueWithBlock:^id(BFTask *task) {
if (task.error) {
if ([task.error.domain isEqualToString:AWSS3TransferManagerErrorDomain]) {
switch (task.error.code) {
case AWSS3TransferManagerErrorCancelled:
{
//LogError(@"AWS Cancelled - Upload failed: [%@]", task.error);
break;
}
case AWSS3TransferManagerErrorPaused:
{
LogError(@"AWS Paused - Upload failed: [%@]",task.error);
}
break;
default:
LogError(@"AWS status [%ld]:Upload failed: [%@]",(long)task.error.code,task.error);
break;
}
} else {
LogError(@"Upload failed: [%@]", task.error);
}
}
if (task.result) {
dispatch_async(dispatch_get_main_queue(), ^{
LogDebug(@"Upload ok: [%@]", task.error);
});
}
return nil;
}];
}
我该如何解决?