0
我正在生成一個簡單的scrollView,其中一些圖像附加到按鈕上。 這個工作很好,除了這個滾動視圖佔用了很多內存。當前從多個圖像的UIScrollview釋放內存的方式
因爲這個scrollView只是一個子菜單,允許用戶選擇一個圖像,不久之後我不需要它,我想從內存中釋放這個沉重的塊。
你能好心幫助我理解這個問題,並免費在不需要時
int flipFlop = 1;
masksAvailable = 18;
float topMaskXX = 85.0;
float topMaskYY = 96.0;
UIButton *button;
for (int buttonsLoop = 1;buttonsLoop < masksAvailable+1;buttonsLoop++){
button = [UIButton buttonWithType:UIButtonTypeCustom];
NSString *tempname = [NSString stringWithFormat:@"mask_frame%i.png",buttonsLoop];
// This fellow there is the memory eating monster
[button setBackgroundImage:[UIImage imageNamed:tempname] forState:UIControlStateNormal];
tempname = nil;
button.tag = buttonsLoop;
[button addTarget:self action:@selector(handleMaskKeys:) forControlEvents:UIControlEventTouchUpInside];
UIImageView *frameForSubImages = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image_frame.png"]];
frameForSubImages.frame = CGRectMake(0.0, 0.0, 320.0/2.9, 480.0/2.9);
frameForSubImages.center = CGPointMake(topMaskXX,topMaskYY);
[scrollView addSubview:frameForSubImages];
button.frame = CGRectMake(0.0, 0.0, 320.0/3.4, 480.0/3.4);
button.center = CGPointMake(topMaskXX,topMaskYY);
if (flipFlop == 1){
topMaskXX += 150;
} else {
topMaskYY += 185.0;
topMaskXX = 85.0;
}
flipFlop = flipFlop * -1;
[scrollView addSubview:button];
}