Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-26-2008, 09:48 AM   #1 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 2
koka is on a distinguished road
Default 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!
koka is offline   Reply With Quote
Old 05-05-2009, 09:55 AM   #2 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 20
sanniv is on a distinguished road
Default

Finally got the right way to use UIImageView, I explained here-- iPHone Programming Guide / Tips

Quote:
Originally Posted by koka View Post
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!
sanniv is offline   Reply With Quote
Reply

Bookmarks

Tags
memory, memory management, uiimageview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 349
11 members and 338 guests
akacaj, c2matrix, cgokey, esoteric, givensur, HemiMG, Mirotion22, mjnafjke, Pudding, SLIC, Techgirl-52
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,651
Threads: 94,115
Posts: 402,887
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Mirotion22
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:15 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0