지도에서 일부 타일을 표시하는 iPhone 앱을 개발 중입니다. 타일을 인터넷이나 파일 시스템에서로드하는 스레드가 있습니다. 이것은iPhone 메모리 충돌 : 신호 0
내 생각이 무단 쓰레드에서 타일로로드된다는 것이다 .. 메모리 부족이 IM 수단 신호를 0으로 많은 타일을 응용 chrashes를 표시 한 후 무단 스레드에게
while(true){ //get tile into cache }
Unfortunateley 인
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
while(true){
UIImage * img = nil;
NSFileHandle * tile = [NSFileHandle fileHandleForReadingAtPath:filePath];
if(tile){
NSData * data = [tile readDataToEndOfFile];
if(data){
img = [[UIImage alloc] initWithData:data];
local = YES;
}
}
if(img == nil){
NSURL * url = [NSURL URLWithString: [NSString stringWithFormat:@"http://tile.openstreetmap.org/%@.png", todoKey ] ];
img = [[UIImage alloc] initWithData: [NSData dataWithContentsOfURL: url options:NSDataReadingMapped error:&error] ];
}
if(img != nil){
[cache addObject:img]; //cache is an array of tiles
}
[img release];
[self cleanupCache]; //method to check if cache is full, and if so remove's objects from it
}
[pool release];
임은 autoreleasep 생각 : 오토 릴리즈, 그리고 ..
는 기본적으로 내 끝없는 스레드에서이 일을 메신저 오토 릴리즈 노된다 ool은 "죽은"참조를 수시로 정리하지 않으며, 모든 타일은 메모리에 보관됩니다. 악기 누설을 검사 할 때 메모리 누수가 없지만 '라이브 메모리'가 계속 누적됩니다.
왜 이런 일이 발생하고 그것을 막을 수있는가?
왜 무한 루프가 필요합니까? – MCannon
내 루프가 요청하면이 루프에서 요청 타일을 다운로드합니다. '이 타일을 가지고 있습니까?'스레드가이를 다운로드하여 캐시에 저장합니다. – Nick