2011-12-08 66 views
0

以下是我上傳日誌文件到FTP的代碼,並且問題有時會在執行[mInputStream打開]時崩潰。 XCode顯示我BAD_ACCESS。我想這可能是上傳一個大尺寸文件的結果。但是,有時會發生BADACCESS,即使文件大小也很小。所以我猜尺寸不是主要原因。任何人都可以幫忙太感謝了。NSInputStream打開BAD_ACCESS

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]; 

回答

1

首先,retainCount是無稽之談。別叫它。不要試圖瞭解返回的值。

其次,你的應用程序崩潰。這意味着有一個崩潰日誌或回溯。發表它。

最後,你的問題被標記爲iOS,但你打電話給NSMakeCollectible();這沒有意義。此外,這裏似乎還有一些內存管理問題。你有沒有嘗試建立和分析?