Hi,
In my application that I am creating, I need to create multiple UIImageViews. I do this using code in a while loop. All of this works perfectly on the iPhone Simulator. However, when I try to run it on my actual iPhone, the program crashes and in the bottom right of XCode, I see "GDB: Program Received Signal: "0".
I don't know what I am doing wrong, but could it be due to memory management issues? When in my while loop would (if anywhere) should I release the image view? Also, should I declare the imageview as an instance, or only declare it when I need it?
Try looking up NSAutoReleasePool. The general memory management behavior is to drain the autorelease pool once through the event loop. If you're allocating lots of autorelease objects without allowing the event loop to run, it's possible to accumulate a lot of these objects.
There's also a good chance that you're simply allocating too many objects to be used at the same time. Images are notorious for taking up large amounts of memory. Make sure they're not bigger than they need to be.
__________________
iPhoneApps: enLegion - When everyone needs to be in the same place, but isn't AutoWeb - Automate your web logins and browsing!
Try looking up NSAutoReleasePool. The general memory management behavior is to drain the autorelease pool once through the event loop. If you're allocating lots of autorelease objects without allowing the event loop to run, it's possible to accumulate a lot of these objects.
There's also a good chance that you're simply allocating too many objects to be used at the same time. Images are notorious for taking up large amounts of memory. Make sure they're not bigger than they need to be.
Thanks for the suggestion. How would I make it so that the AutoReleasePool can run?
I should also mention that I got rid of my loop for testing purposes, and ran my event every time that I pressed a button. The iPhone was only able to generate only 4 or 5 images before crashing. Yet again, however, the simulator was able to put all of the images up on the screen.
Update:
I was testing my app with Instruments, and it seems that the images may not be my problem. As it turns out, compared to the other allocations in my app, images are relatively low. It seems that the major culprits are strings and numbers. This seems like it could be the case because every time the loop runs, I need to generate a random number, and a string with the random number in it. (This is how I choose random images). How do I release those strings and numbers so that I don't have so many allocations?
Ah, if that's the case, it's likely that you're leaking image objects.
Would help to post the code you're using to generate your images and where you're deallocating them.
__________________
iPhoneApps: enLegion - When everyone needs to be in the same place, but isn't AutoWeb - Automate your web logins and browsing!
Hi,
In my application that I am creating, I need to create multiple UIImageViews. I do this using code in a while loop. All of this works perfectly on the iPhone Simulator. However, when I try to run it on my actual iPhone, the program crashes and in the bottom right of XCode, I see "GDB: Program Received Signal: "0".
I don't know what I am doing wrong, but could it be due to memory management issues? When in my while loop would (if anywhere) should I release the image view? Also, should I declare the imageview as an instance, or only declare it when I need it?
Thanks in advance!
Are your images larger than 1024x1024? The docs recommend shrinking them before displaying. Also, are you using imageNamed: to load them? That method caches an extra copy of the image in-memory, in case you need to load it again. Use imageWithContentsOfFile instead.
Also, if you're creating something like a slideshow, you don't want to create 100 imageViews and hide 99 of them. You want to load the images one at a time, "lazily," as you need them. Or maybe 2-3 at a time (previous,current,next) to allow fast display.
Here is my code. What I basically am trying to do is draw a lot (96!) random images across the iPhone screen. I believe mosaicPieces is an ImageView that I declared in the .h file and release in the dealloc method. I am also loading the images from the Documents Directory. When the user picks them, the app writes them as jpegs, with compression of .1.
Are your images larger than 1024x1024? The docs recommend shrinking them before displaying. Also, are you using imageNamed: to load them? That method caches an extra copy of the image in-memory, in case you need to load it again. Use imageWithContentsOfFile instead.
Also, if you're creating something like a slideshow, you don't want to create 100 imageViews and hide 99 of them. You want to load the images one at a time, "lazily," as you need them. Or maybe 2-3 at a time (previous,current,next) to allow fast display.
Thanks again! How would I resize the image. I really only need the images to be maybe 50 x 50 (at most). 20 x 20, would work perfectly, though, as that resolution would make all of my images combined the exact resolution of the iPhone screen.
Never mind. I searched other forums on how to resize images from the image picker. Now it works perfectly, without crashing, and it runs very quickly. Thanks a ton for your help!
Never mind. I searched other forums on how to resize images from the image picker. Now it works perfectly, without crashing, and it runs very quickly. Thanks a ton for your help!
i'm new to this xcode. i developing app. In that app i'm calling 30 header files through button event. when i click the button consecutively after five times the app will closed..
Cn u help me???
Thanks in Advance.....
Last edited by prakaashnk; 10-19-2010 at 01:06 AM.
Reason: detail
i'm new to this xcode. i developing app. In that app i'm calling 30 header files through button event. when i click the button consecutively after five times the app will closed..
Cn u help me???
Thanks in Advance.....
Sounds like a memory error, but could be something else. What do you see in the console when it crashes? Post the code from the button method too.
Sounds like a memory error, but could be something else. What do you see in the console when it crashes? Post the code from the button method too.
Thanks for reply..
This is for ipad..
The Console output :
Data Formatters temporarily unavailable, will re-try after a 'continue'. (Unknown error loading shared library "/Developer/usr/lib/libXcodeDebuggerSupport.dylib")
Thanks for reply..
This is for ipad..
The Console output :
Data Formatters temporarily unavailable, will re-try after a 'continue'. (Unknown error loading shared library "/Developer/usr/lib/libXcodeDebuggerSupport.dylib")
What's before that? That's just a note from the debugger and not information about the crash. Post the code from the button method too.