我正在開發一個iPhone應用程序,它顯示地圖上的一些圖塊。我有一個從互聯網或文件系統加載磁貼的線程。這是一個永無止境的線程iPhone內存崩潰:信號0
while(true){ //get tile into cache }
Unfortunateley顯示多少瓷磚信號0,這意味着IM出內存的應用chrashes後..
我的想法是,在這無盡的線程的瓦片被加載自動釋放,並自動釋放NOG ..
基本上即時通訊在我無盡的線程這樣:
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 2011-03-24 08:15:17
在這個循環中,我正在按需下載瓷磚,如果我的觀點問:'你有這些瓷磚嗎?「線程負責下載它們並將它們放入緩存。 – Nick 2011-03-24 09:17:17