Dear Scholars. I am generating a simple scrollView with some images attached to buttons. This works fine apart from the fact that this scroll view is taking rather much memory.
Since this scrollView is just a sub Menu allowing the user to pick an image and soon after I do not need it, I would like to free this heavy block from memory.
Can you kindly help me out understanding this issue, and free this huge memory block when not needed
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];
}