UIImageView and Memory Management
Hi there,
I'm trying to loop through a set of images and display them in a UIImageView every time a user moves a certain amount of pixels with the touchesMoved event.
The app works fine in the simulator but on the iPhone it goes through the first few images and then it crashes. I'm guessing it's a memory management issue and was wondering if someone could point me in the right direction.
The images are around 100k each and there's about 20 of them. Here's is some of the setup:
I have the UIImageView view declared in the .h file as:
...
IBOutlet UIImageView *imageView;
...
@property (nonatomic,retain) IBOutlet UIImageView *imageView;
Then I synthesize it in the .m file:
...
@synthesize imageView;
In the touchesMoved event I have:
...
imageView.image = [UIImage imageNamed:@"imageName.png"];
...
In the dealloc method I have:
...
[imageView release];
...
So every time the user moves a certain amount of pixels I replace the image of the imageView. I get the image name from a predefined array of image names. After the last image is displayed I start from the first one - creating a loop.
From what I understand when using assignments like imageNamed in this case you don't need any immediate memory release as it was not assigned using alloc.
There must be a more memory efficient way of replacing the images in the imageView to preserve the memory and prevent the app from crashing.
Any advice would be much appreciated.
Thank you!
|