Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to reuse variable to avoid abandoned memory
    text
    copied!<p>I've got a TapDetectingImageView class that is pertaining in memory after usage because I do not reuse it in my code. I change my code now to reuse it instead of re creating a new one each time.</p> <p>The goal is to configure that TapDetectingImageView object and put it in a view. I'll do it 8 times but with the code below, only the last one is showing. I'm sure I'm missing something, but what? ;)</p> <p>The view holding the imageViews is potatoeView. I'm adding new TapDetectingImageView through:</p> <pre><code>[potatoeView addSubview:imageView]; </code></pre> <p>What's wrong in that code?</p> <pre><code>for (int i = 0; i &lt;= numberOfPotatoes-1; i++) { NSLog(@"potatoesView Generation : %d",i); NSArray *imgArray = [[NSArray alloc] initWithArray:[p objectAtIndex:i]]; UIImage *img1 = (UIImage *) [imgArray objectAtIndex:0]; UIImage *img2 = (UIImage *) [imgArray objectAtIndex:1]; NSString *imgName = (NSString *) [imgArray objectAtIndex:2]; if (imageView == nil) { imageView = [[TapDetectingImageView alloc] initWithImage:img1 imageHighlighted:img2]; }else { [imageView setImage:(UIImage *)img1]; [imageView setImageHighlighted:(UIImage *)img2]; } [imageView setDelegate:self]; // setup each frame to a default height and width, it will be properly placed when we call "updateScrollList" CGRect rect = imageView.frame; rect.size.height = [potatoesSize floatValue] ; rect.size.width = [potatoesSize floatValue] ; imageView.frame = rect; [imageView setName:(NSString *)imgName]; imageView.tag = i+1; // tag our images for later use when we place them in serial fashion NSValue *val = [potatoesSizeAndPositions objectAtIndex:i]; CGPoint point = [val CGPointValue]; imageView.center = point; [potatoeView addSubview:imageView]; [imgArray release]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload