Subscribe ( )

iPhone Programming Tutorials


 

Forum

You must be logged in to post Login Register

Search 

UIImageView and Memory Management

User Post

7:59 am
September 26, 2008


nj

Noob

posts 3

1

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!

9:32 am
September 26, 2008


Admin

brandontreb

posts 88

2

You should be able to check the error dump inside of the console.  That might provide some insight as to why your app is crashing.  Go ahead and paste it here so that we may further troubleshoot the issue.

If debugging is the process of removing bugs, then programming must be the process of putting them in.
-Edsger Dijkstra

6:00 pm
September 26, 2008


nj

Noob

posts 3

3

Hi Brandon,

Thanks for the reply. Here's what I get in the console:

“Terminating in response to SpringBoard's termination.

Debugger stopped.
Program exited with status value:0.”

Don't know how helpfull this is.

The app is navigation controlled and consists of 3 levels. I know the error could potentially be caused in the other 2 views but I can have it running in those views for a long time without crashing. As soon as I push the 3rd view on and start flipping the images it crashes.

I wonder if the images are autoreleased properly or if there's an alternative way of assigning them to the image view so they don't consume all the memory.

Thanks again!

10:38 am
September 27, 2008


nj

Noob

posts 3

4

I've been doing more investigation into the issue and I'm starting to be a bit more suspicious of the overall navigation controller memory management.

I have 3 levels of navigation in my app, let's call them Level 1, Level 2 and Level 3. Level 1 loads fine with a list of entries from which we can select one and go to Level 2. Level 2 loads fine with some detail information about the entry and from here we can go to Level 3 for further details. Level 3 loads fine and here we can do all the image replacements fine (this is where I thought the initial problem was) but…

From here (Level 3) we can go back to Level 2 and then Level 1 without any problems. Now if I try to do the same thing but for any other different item from the list once I reach its Level 3 and thy to do the image replacements the app crashes. This is why I initially thought the problem was at this level but now I think that it doesn't have to be.

By the time we reach this point a lot of memory has been allocated to the app and obviously if it's not properly managed the app will crash (as it does). I release all memory allocated to objects using “alloc” as I go along. I also call release on all the objects in the “dealloc” method.

One thing that's puzzling me at the moment is…

All along the way as I was going through the scenario I described above I had debug breakpoints set on each of the view controllers' dealloc methods. None of them get called before the app crashes. When do the dealloc methods get called? If I'm going up and down my navigation hierarchy memory gets accumulated but if the dealloc methods don't get called the memory never gets released.

I know it hard to judje without any code but could this potentially be the problem? How can I ensure the dealloc methods get called to relsease the memory?

Any feedback would be much appreciated.

Thank you!

Search 

About the iCodeBlog forum

Most Users Ever Online:

44


Currently Online:

3 Guests

Forum Stats:

Groups: 2

Forums: 6

Topics: 419

Posts: 893

Membership:

There are 934 Members

There has been 1 Guest

There are 2 Admins

There is 1 Moderator

Top Posters:

bobcubsfan – 54

crazyiez – 30

Uhu – 17

AdeC – 17

Nick – 15

jitesh61 – 12

Administrators: Brandon (88 Posts), Collin (0 Posts)

Moderators: VertigoSol (26 Posts)



©   

  • Posted by on 6 Aug 2008 in Uncategorized
  •   |  
  •   |  
  •   |  
  • Comments Off

Comments are closed.