views:

539

answers:

1

I am working on a photo gallery app. Root view is a navigation controller which takes the user to the thumbnail view. Tapping any thumbnail takes the user to PhotoView which shows the tapped image in full screen.

Below is what I have done in my PhotoViewController:

The approach is pretty much similar to the ScrollingMadness project which I found at github.

I initialize a UIScrollView and add it as a subView to my view controller's view. Set some basic properties of UIScrollView. Add images to UIImageViews (5 in numbers). Add all these imageViews as a subview to UIScrollView. When zoom operation is performed on any image, all the image subviews but the current one are removed from the scroll view. When the image zooms out back to the minimum scale, all the images are added back to the UIScrollView.

As explained in the sample code from Apple, I am using TapDetectingImageView delegate to create the imageViews and handling touch events.

When I run the app, everything works fine in simulator. No issues whatsoever. But when I run the app in device, it crashes after I scroll to 3rd or 4th image. While debugging I found out that didReceiveMemory warning is called after I scroll to 3rd or 4th image. I run the app using Instruments. The object allocations shows allocation levels to only 1.5-2MB when the crash happens. I believe memory usage to this level is very normal ... right?

Anyone who experienced this before OR any input as to how I can get rid of it... would be all the help I need in world at this time.

Let me know in case you need any other info.

PS > Its frustrating to see the whole app perfect in simulator but crashing in the device :(

+2  A: 

It is crashing because its running out of memory, one thing you should check is the size of the pictures, are you picking the image from the photo library w/o editing, sometimes this will give u images of resolution of 1600x1400 which will pretty much just crash the phone because it runs out of memory, for this you should just resize your images to smaller ones. Another problem that could be causing it is you are loading too many images at once (i dont think so though), if you are using t he scroll view to have a scrolling similar to the photo application on the Iphone then you should only need to load 3 images at a time. Also maybe you arent r eleasing the images properly when you are zooming . I dont know if you a re trying to accomplish a similar functionality to the scrolling of pictures in the photo app on iphone, if you are look at the sample project PageControl, they illustrate that pretty well there.

Daniel
Daniel - you are pixel perfect right!!! The images were 1200X1600. I shred them down to 320x480 it works like a charm.The number of images I have used right now is 5. But eventually I will have to use 20 Images. If you could please suggest how to lazy laod imageViews or about loading 3 images at a time as you mentioned - would be great help.Zooming-in-out part has been taken care of. Nothing goes in and out of the memory. Its just the in-out stuff on subview for the contents already in memory.Thanks for your help!
AJ
Look at the sample project PageControl in the apple iphone developer site, it has a good example of how to achieve what you want
Daniel