문자열을 디렉토리 경로로 반환하는 함수를 작성했습니다. EXC_BAD_ACCESS가 표시되며이 함수가 원인이라고 생각합니다. nstring 또는 다른 것을 유지해야합니까?NSString을 할당 할 때 EXC_BAD_ACCESS 가져 오기
-(void) getRemoteFiles:(NSMutableArray *) M
{
[self createFileToAppDirectory];
if (!networkqueue) {
networkqueue:[[[ASINetworkQueue alloc] init] autorelease];
}
[[self networkQueue] cancelAllOperations];
[self setNetworkQueue:[ASINetworkQueue queue]];
[[self networkQueue] setDelegate:self];
[[self networkQueue] setRequestDidFinishSelector:@selector(requestFinished:)];
[[self networkQueue] setRequestDidFailSelector:@selector(requestFailed:)];
[[self networkQueue] setQueueDidFinishSelector:@selector(queueFinished:)];
int i;
for (i=0; i<[M count]; i++) {
NSString *url=[M objectAtIndex:i];
NSString* theFileName = [url lastPathComponent];
NSString *safestring=[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
if ([theFileName isEqualToString:@"nothing"]==NO) {
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:safestring]];
//think this is causing the problem
NSString *savepath=[self getDirectoryPathForFileName:theFileName];
//[request setDownloadDestinationPath:savepath];
[[self networkQueue] addOperation:request];
}
}
[[self networkQueue] go];
//error thrown after this point
}
-(NSString *)getDirectoryPathForFileName:(NSString *)filename
{
NSFileManager *filemgr;
NSArray *dirPaths;
NSString *docsDir;
NSString *newDir;
BOOL isDir;
filemgr =[NSFileManager defaultManager];
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
newDir = [docsDir stringByAppendingPathComponent:@"remix_data"];
if ([filemgr fileExistsAtPath:newDir isDirectory:&isDir]==NO) {
NSLog(@"dir should exist but does not... go funt dat");
}
NSString *localFilePath = [newDir stringByAppendingPathComponent:filename];
[filemgr release];
[docsDir release];
[newDir release];
return localFilePath;
}
filemgr, docsDir 및 newDir에서 alloc/init을 수행하지 않습니다. 그럼 왜 그걸 풀어주는거야? –
나는 여전히 메모리 관리에 대해 배우고 있으며 코드는 예제에서 나온 것이다. 나는 그 예가 잘못되었다고 생각하니? – dubbeat