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 03-24-2009, 05:53 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 109
brian515 is on a distinguished road
Default App crashes due to memory management problem

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!
brian515 is offline   Reply With Quote
Old 03-24-2009, 06:58 PM   #2 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 60
substance21 is on a distinguished road
Default

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!
substance21 is offline   Reply With Quote
Old 03-24-2009, 07:55 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 109
brian515 is on a distinguished road
Default

Quote:
Originally Posted by substance21 View Post
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.

Thanks for your help!
brian515 is offline   Reply With Quote
Old 03-24-2009, 08:03 PM   #4 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 109
brian515 is on a distinguished road
Default

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?
brian515 is offline   Reply With Quote
Old 03-24-2009, 08:03 PM   #5 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 60
substance21 is on a distinguished road
Default

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!
substance21 is offline   Reply With Quote
Old 03-24-2009, 08:09 PM   #6 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Quote:
Originally Posted by brian515 View Post
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.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 03-24-2009, 08:09 PM   #7 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 109
brian515 is on a distinguished road
Default

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.
Code:
-(IBAction)startCreating {
	while (imageNumber <=96) {
		if(xcordinate == 320) {
			xcordinate = 0;
			ycoordinate = ycoordinate + 40;
		}
		mosaicPieces = [[[UIImageView alloc] initWithFrame:CGRectMake(xcordinate, ycoordinate, 40, 40)] autorelease];
		NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);	
		NSString *imageDirectory = [path objectAtIndex:0];
		numberOfImages = [[NSUserDefaults standardUserDefaults] integerForKey:@"photoNumber"];
		randomPhotoNumber = arc4random() % numberOfImages;
		NSString *photoTemp = [NSString stringWithFormat:@"piece%i.jpg", randomPhotoNumber];
		imageDirectory = [imageDirectory stringByAppendingPathComponent:photoTemp];
		mosaicPieces.image = [UIImage imageWithContentsOfFile:(NSString *)imageDirectory];
		[mosaicView addSubview:mosaicPieces];
		mosaicPieces.contentMode = UIViewContentModeScaleAspectFill;
		mosaicPieces.clipsToBounds = YES;
		imageNumber = imageNumber + 1;
		xcordinate = xcordinate + 40;
	}
}
brian515 is offline   Reply With Quote
Old 03-24-2009, 08:38 PM   #8 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 109
brian515 is on a distinguished road
Default

Quote:
Originally Posted by smasher View Post
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.
brian515 is offline   Reply With Quote
Old 03-24-2009, 08:45 PM   #9 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 109
brian515 is on a distinguished road
Default SOLVED

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!
brian515 is offline   Reply With Quote
Old 01-28-2010, 02:07 AM   #10 (permalink)
Registered Member
 
vikysaran's Avatar
 
Join Date: Jul 2009
Location: New Delhi
Posts: 130
vikysaran is on a distinguished road
Unhappy

Quote:
Originally Posted by brian515 View Post
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!
could you tell me which blog you followed?
__________________
Thanx & Regards-
Vaibhav Saran | Software Engineer
Neo Sypher Systems Pvt. Ltd.
New Delhi | India
Websites:
http://www.iphonesaura.com/
http://www.apptango.com/

vikysaran is offline   Reply With Quote
Old 10-18-2010, 01:01 AM   #11 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 3
prakaashnk is on a distinguished road
Default App closed due to memory full

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
prakaashnk is offline   Reply With Quote
Old 10-18-2010, 10:39 PM   #12 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Quote:
Originally Posted by prakaashnk View Post
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.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 10-19-2010, 01:13 AM   #13 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 3
prakaashnk is on a distinguished road
Default

Quote:
Originally Posted by smasher View Post
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")
prakaashnk is offline   Reply With Quote
Old 10-19-2010, 09:33 AM   #14 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Quote:
Originally Posted by prakaashnk View Post
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.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 12-11-2010, 04:34 AM   #15 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 3
prakaashnk is on a distinguished road
Default Can support Core plot framework in iOS 4.2?

hi... Can support Core plot framework in iOS 4.2? Bec
in my app crashes when i click graph function...

The Error message is

The Debugger has exited due to signal 15 (SIGTERM).The Debugger has exited due to signal 15 (SIGTERM).
prakaashnk is offline   Reply With Quote
Reply

Bookmarks

Tags
imageview, loop, memory leak, memory management, signal 0

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: 332
3 members and 329 guests
guusleijsten, Kryckter, LEARN2MAKE
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,880
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

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