gpt4 book ai didi

objective-c - NSInputStream 打开 BAD_ACCESS

转载 作者:行者123 更新时间:2023-11-29 04:53:27 24 4
gpt4 key购买 nike

下面是我上传日志文件到FTP的代码,问题是有时执行[mInputStream open]时会崩溃。 XCode 显示 BAD_ACCESS。我猜这可能是由于上传大文件造成的。然而,即使文件很小,有时也会发生BADAACCESS。所以我想尺寸不是主要原因。有人可以帮忙吗?谢谢一百万。

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

最佳答案

首先,retainCount是无稽之谈。别叫它。不要试图理解返回的值。

其次,您的应用程序崩溃了。这意味着存在崩溃日志或回溯。发布它。

最后,您的问题被标记为 iOS,但您正在调用 NSMakeCollectible();这没有道理。此外,这里似乎还存在许多内存管理问题。您尝试过构建和分析吗?

关于objective-c - NSInputStream 打开 BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8424927/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com