下面是我将日志文件上传到FTP的代码,问题是有时候在执行[mInputStream open]时会崩溃。 XCode告诉我BAD_ACCESS。我想这可能是因为上传一个大尺寸的文件。但是,有时会发生BADACCESS,即使文件大小很小。所以我猜大小不是主要原因。有人可以帮忙吗?万分感谢。
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
BOOL success;
NSURL *url;
CFWriteStreamRef ftpStream;
mFinish = NO;
mUploadPath = [[NSString alloc] initWithFormat:@"%@/%@",[UtilityHelper logFolderPath], [mPathList objectAtIndex:0]];
//NSLog(@"mUpLoadPath:%d",[mUploadPath retainCount]);
[mPathList removeObjectAtIndex:0];
// check url
url = [UtilityHelper smartURLForString:FTP_URL];
url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", url.absoluteString, [[UIDevice currentDevice] uniqueIdentifier]]];
success = (url != nil);
if (success) {
url = [NSMakeCollectable(CFURLCreateCopyAppendingPathComponent(NULL, (CFURLRef) url, (CFStringRef) [mUploadPath lastPathComponent], false) ) autorelease];
success = (url != nil);
}else
return;
mInputStream = [[NSInputStream inputStreamWithFileAtPath:mUploadPath] retain];
[mInputStream open];
// Create CFFTPStream for the URL
ftpStream = CFWriteStreamCreateWithFTPURL(NULL, (CFURLRef) url);
assert(ftpStream != NULL);
mNetworkStream = [(NSOutputStream*)ftpStream retain];
NSLog(@"<<<<<<**>retain count:%d", [mNetworkStream retainCount]);
success = [mNetworkStream setProperty:FTP_USERNAME forKey:(id)kCFStreamPropertyFTPUserName];
assert(success);
success = [mNetworkStream setProperty:FTP_PWD forKey:(id)kCFStreamPropertyFTPPassword];
assert(success);
//[mNetworkStream self
mNetworkStream.delegate = self;
[mNetworkStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[mNetworkStream open];
CFRelease(ftpStream);
[pool release];
答案 0 :(得分:1)
首先,retainCount
是无稽之谈。不要打电话给它。不要试图理解返回的值。
其次,您的应用程序正在崩溃。这意味着存在崩溃日志或回溯。发布它。
最后,您的问题标记为iOS,但您正在调用NSMakeCollectible()
;这没有意义。此外,这里似乎存在许多内存管理问题。你尝试过Build and Analyze吗?