Quote:
Originally Posted by AlexTheMighty
Don't see any leaks (as long as you make sure to remove the "pic" view later instead of just creating a new UIImage view on top of it. (Also if you want to check code for leaks, the Leaks tool included in the XCode env is great for exactly this sort of thing, and is defiantly something to learn how to use).
My question would be though, if you use this view a lot and are constantly calling this code, why not just keep the UIImageView around and simply replace the image it contains? Constantly creating a new UIImageView seems like the roundabout way of replacing an old image. Save yourself (and the device) some work and just do it once.
|
Thank you for your quick reply! The reason I don't replace the image is that I want the picture to remain visible for the duration of animation... when I replace it, then the old picture disappears... if you understand what I mean. The actual code I use (which I didn't mention in the thread to make things simple) is:
- (void)showTouchedPoint_XCoord

float)XCoord YCoord

float)YCoord {
UIImageView *touchedPointImageView = [[UIImageView alloc] init];
touchedPointImageView.image = [UIImage imageNamed:@"touchedPoint.png"];
touchedPointImageView.frame = CGRectMake(XCoord, YCoord, 20, 20);
touchedPointImageView.alpha = 0.8;
[self.view addSubview:touchedPointImageView];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
touchedPointImageView.alpha = 0.0;
[UIView commitAnimations];
[touchedPointImageView release];
}
Can you please have a look at it again and tell me if this is ok? Also when I release the imageview, then the allocated uiimageview object is freed and so is the memory for that object, right? (sorry for the noobiness of the question.)