我有一個被稱爲一個循環方法,看起來是這樣的範圍內:釋放renderInContext導致一個循環
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
UIImageView *background = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, PAGE_WIDTH, PAGE_HEIGHT)];
background.image = backgroundImg;
for (UIView *view in viewArray)
{
[background addSubview:view];
}
UIGraphicsBeginImageContext(background.frame.size);
[background.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
for (UIView *view in background.subviews)
[view removeFromSuperview];
background.image = nil;
[background release];
[image retain];
[pool drain];
[image autorelease];
return image;
然而,根據儀器內存監視器,內存使用情況不斷地增高,並直到循環結束纔會出現。 (這會崩潰。)
如果我更換UIGraphicsBeginImageContext與
的UIImage UIGraphicsEndImageContext *圖像= someotherimage;
那麼內存不會尖峯化,但是由於Autorelease池的原因,我在循環的每次迭代中都會分配和減少內存。 (它不會崩潰)
如果我只是註釋掉renderInContext行它工作正常。 (不會崩潰)
因此,看起來好像renderInContext以某種方式保持在圖像上 - 我怎樣才能讓它釋放它?或者有其他的建議請:)
你是救世主! – 2013-05-15 10:00:26