這是我的代碼,我上面提到的,
的for(int i = 0;我< 10000;我++) { 的printf(「\ n生成圖像。 .............:%d」,i)的; i ++;
UIImageView* imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, spotItem.imageWidth, spotItem.imageHight)];
NSData *receivedData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://sererpath/prudently/iphone/image_s/e545afbf-4e3e-442e-92f9-a7891fc3ea9f/test.png"]];
imageView.image = [[UIImage alloc] initWithData:receivedData] ;
//imageView.image=[UIImage imageNamed:@"1.png"];
[spotItem.subView addSubview:imageView];
[imageView release];
}
我正在直接下載它們。
是的,問題可能是您在循環的每次迭代中創建兩個自動釋放對象('NSData'和'NSURL')。這意味着一旦你的循環結束,自動釋放池將包含至少20,000個項目(並且誰知道這些20,000個項目總共使用了多少內存!)。在我的回答中嘗試遵循我的建議(在循環開始時創建一個NSAutoreleasePool,並在最後釋放它)。 – dreamlax 2010-08-11 12:46:57