Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
From running instruments I see that after I take the image, 8MB or so of space is taken up. But that space never gets released. So each time I take a photo, the memory goes up to hit 40MB which then causes the crash.
What am I doing wrong here? How do I clear the data taken by the UIImagePickerController class so that I'm not causing a crash after 5 pictures?
Maybe someone more familiar with iPhone development could give us a hint concerning this issue. I'm having the same memory issue with the image picker here.
//this is inside my ViewController.m - (IBAction)openPhotolibrary:(id)sender {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
//Now this seems to do the trick. The picker only gets allocated once. Therefore no memory issues any longer! //Before I did it this way, my app crashed after picking 25 images. This one still was OK after picking about 50 images. if (picker == nil) { picker = [[UIImagePickerController alloc] init]; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; picker.allowsImageEditing = YES; picker.delegate = self; } [self presentModalViewController:picker animated:YES]; } }
- (void)useImage:(UIImage *)image { //add code to use the picked image }
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)CurrentPicker { //hide the picker if user cancels picking an image. [[CurrentPicker parentViewController] dismissModalViewControllerAnimated:YES]; }
From running instruments I see that after I take the image, 8MB or so of space is taken up. But that space never gets released. So each time I take a photo, the memory goes up to hit 40MB which then causes the crash.
What am I doing wrong here? How do I clear the data taken by the UIImagePickerController class so that I'm not causing a crash after 5 pictures?
Cheers
I must be missing something.
For every photo (1600x1200 at RGBA, so 8MB), you create a UIImageView which displays the image, of course the memory usage increases by 8MB. About 4 of those full size images will make iPhone run out of memory and crash.
The problem (at least in the above code) is not the image picker, it is your code.
This is still an issue. I've had the same problem. Per the recommendation of other users i created a singleton method on my app delegate to retain an instance of the pickercontroller if/when it's ever called and never release the object until the app shutsdown. I don't like this solution as it goes against everything we're supposed to avoid regarding memory management but i've not found any other method that helps. reasing the picturecontroller does nothing to reduce the memory.
I would love to find out what's going on here.. My app was denied by apple recently because they experienced crashes when picking pictures.. so i added the singleton and resubmitted....
I found out with my application, that it was not the picker controller. I learned that it was what I was doing with the images. Storing one UIImage that came from the camera took up a huge amount of memory. By the time I took 5, it crashed. I started to store my images as NSData instead. Whenever I needed to use the image, I would initialize it with that data. This way, you could release the picker controller and use it like you are suppose to. I found that it works so much better.
i agree that sounds like a good place to look. in my case i'm not letting users pick from the camera only the library. once a picture is chosen i'm compressing it down to a manageable size (< 200k) and i only ever show one image at a time. I'm still digging around but instruments is not showing me anything to go on at the moment.
I do have another screen that displays images.. i like the idea of using nsdata to store them.. will investigate that further.
I am using an UIImagePickerController to get a picture from the users library but I am having trouble doing exactly what i want to do; which is basically as follows:
Say I have a bounding box area specified on the screen (say 128 x 128 pixels). After the user has picked his photo and finalized zoom/scale etc and is done; I want only the area that is inside that bounding box to be retained: saved as it's own image inside the documents folder of the app for later user in the app. It is imperative that only the 128 x 128 final result is saved (for obvious memory reasons).
It's worth noting that the project I am working on is 2D OpenGL based (like GLSprite). Can anyone help me accomplish this?
It was in a new thread that got avoided like the plague; so I figured I'd pester you guys here cause I'm desperate. ;) I didn't think it was really off topic though; because this does have to do with memory management of the UIImagePickerController resulting images...so its close. I thought it was determined that there was no "bug" and its just that the resulting images you end up are mammoth in memory size (8 megs) leading to a crash; so at it's heart, our issues are very related I think.
//this is inside my ViewController.m - (IBAction)openPhotolibrary:(id)sender {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
//Now this seems to do the trick. The picker only gets allocated once. Therefore no memory issues any longer! //Before I did it this way, my app crashed after picking 25 images. This one still was OK after picking about 50 images. if (picker == nil) { picker = [[UIImagePickerController alloc] init]; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; picker.allowsImageEditing = YES; picker.delegate = self; } [self presentModalViewController:picker animated:YES]; } }
- (void)useImage:(UIImage *)image { //add code to use the picked image }
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)CurrentPicker { //hide the picker if user cancels picking an image. [[CurrentPicker parentViewController] dismissModalViewControllerAnimated:YES]; }
i agree that sounds like a good place to look. in my case i'm not letting users pick from the camera only the library. once a picture is chosen i'm compressing it down to a manageable size (< 200k) and i only ever show one image at a time. I'm still digging around but instruments is not showing me anything to go on at the moment.
I do have another screen that displays images.. i like the idea of using nsdata to store them.. will investigate that further.
Thanks! John
I am also having the same problem. Have u rectified it. Then how to compress the captured image plz help me!!
I found out with my application, that it was not the picker controller. I learned that it was what I was doing with the images. Storing one UIImage that came from the camera took up a huge amount of memory. By the time I took 5, it crashed. I started to store my images as NSData instead. Whenever I needed to use the image, I would initialize it with that data. This way, you could release the picker controller and use it like you are suppose to. I found that it works so much better.
Hi, this is my first post in this page, its a great site and i've learned a lot. I have a question for you, i'm building an app where the user can select images i have uiimagepickercontroller and its all ok but how do you do to save those selected images to an image array to show on an imageview inside your app and that keeps that info even when you close and relaunch your app? Thanks in advance, happy coding
Edit: user picks images from photolibrary, not from camera
If you're displaying this view once for each image selection, then you will be creating a memory leak by allocating the image picker, but not releasing it.
The Apple sample releases the UIImagePickerController after an image has been selected. Your code doesn't do this.
This is the way to do it: [picker release];
or
[picker autorelease];
From the code you posted, you're not doing this, so the previous allocs are sitting around in memory.
The reason your solution below alleviates the problem is that because you're conditionally allocating the picker, you only do it once.
Just thought I'd point this out to solve the mystery :)
Replies
A lot of the sample code you see online doesn't seem to do that.
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesomeimagepicker is deallocated in the dealloc function of my parent view controller.
Now, after a person takes a photo I do the following:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo{
//we need to save each image and then show it in the interface!
int row = (self.numPhotos / 4);
int mod = self.numPhotos % 4;
UIImageView *imageview = [[UIImageView alloc] initWithImage:image];
[imageview setFrame:CGRectMake(mod * 80.0, row*120.0 + 120.0, 80.0, 120.0)];
[self.view addSubview:imageview];
[imageview release];
self.numPhotos = self.numPhotos + 1;
[self.navigationController dismissModalViewControllerAnimated:YES];
}
From running instruments I see that after I take the image, 8MB or so of space is taken up. But that space never gets released. So each time I take a photo, the memory goes up to hit 40MB which then causes the crash.
What am I doing wrong here? How do I clear the data taken by the UIImagePickerController class so that I'm not causing a crash after 5 pictures?
Cheers
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeFriendlydeveloper - Coding Blog
Codingsessions - Live iOS Training
iPhone Apps:
<a hr
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeThanks,
Michael.
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesomelet me share the piece of code with you, that finally solved my memory issues!
Hope this helps.
Friendlydeveloper - Coding Blog
Codingsessions - Live iOS Training
iPhone Apps:
<a hr
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeThe Airsource - Memory usage in UIImagePickerController
Airsource - Mobile Software Experts
The Airsource - A blog on mobile software
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeFor every photo (1600x1200 at RGBA, so 8MB), you create a UIImageView which displays the image, of course the memory usage increases by 8MB. About 4 of those full size images will make iPhone run out of memory and crash.
The problem (at least in the above code) is not the image picker, it is your code.
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeThank you...
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeCan anyone confirm that this is still an issue?
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeI would love to find out what's going on here.. My app was denied by apple recently because they experienced crashes when picking pictures.. so i added the singleton and resubmitted....
John
I love being a dad, flying airplanes and writing code.
----------------------------------------------------------------------
Follow me on Twitter: <a href=
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeI do have another screen that displays images.. i like the idea of using nsdata to store them.. will investigate that further.
Thanks!
John
I love being a dad, flying airplanes and writing code.
----------------------------------------------------------------------
Follow me on Twitter: <a href=
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeSay I have a bounding box area specified on the screen (say 128 x 128 pixels). After the user has picked his photo and finalized zoom/scale etc and is done; I want only the area that is inside that bounding box to be retained: saved as it's own image inside the documents folder of the app for later user in the app. It is imperative that only the 128 x 128 final result is saved (for obvious memory reasons).
It's worth noting that the project I am working on is 2D OpenGL based (like GLSprite). Can anyone help me accomplish this?
[IMG]http://www.omegasoftweb.com/omega/omegasoftIconBanner.png[/IMG]
Aura Trainer | <a href="http://bi
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome[IMG]http://www.omegasoftweb.com/omega/omegasoftIconBanner.png[/IMG]
Aura Trainer | <a href="http://bi
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeJohn
I love being a dad, flying airplanes and writing code.
----------------------------------------------------------------------
Follow me on Twitter: <a href=
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome[IMG]http://www.omegasoftweb.com/omega/omegasoftIconBanner.png[/IMG]
Aura Trainer | <a href="http://bi
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeFor Tutorials on iPhone check out http://adeem.me/blog
iPhone Tutorial on Demand!
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesomehttp://codecruncher.wordpress.com
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesomehttp://codecruncher.wordpress.com
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeI am picking an image with a UIImagePickerControl with the code
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhoto) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
I need to pas this image data to next view
i got the code for taking image data representation
UIImage *img = [UIImage imageNamed:@"some.png"];
NSData *dataObj = UIImageJPEGRepresentation(img, 1.0);
how can I get the image representation of same image that i am taking with UIImagePickerControl
Can u pls send me the code to use that image ?
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeEdit: user picks images from photolibrary, not from camera
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeThe Apple sample releases the UIImagePickerController after an image has been selected. Your code doesn't do this.
This is the way to do it:
[picker release];
or
[picker autorelease];
From the code you posted, you're not doing this, so the previous allocs are sitting around in memory.
The reason your solution below alleviates the problem is that because you're conditionally allocating the picker, you only do it once.
Just thought I'd point this out to solve the mystery :)
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome