Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 09-30-2008, 04:15 AM   #7 (permalink)
NewiPhoneDeveloper
Registered Member
 
Join Date: Jul 2008
Posts: 459
Default

Hi there,

let me share the piece of code with you, that finally solved my memory issues!

Code:
//this is my ViewController.h

@interface myViewController: UIViewController <UIImagePickerControllerDelegate> {
UIImagePickerController *picker;
}

@property (nonatomic, retain) UIImagePickerController *picker;

- (IBAction)openPhotolibrary:(id)sender;
- (void)useImage:(UIImage *)image;

@end
Code:
//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];
}

- (void)dealloc {
    [picker release];
    [super dealloc];
}
Hope this helps.

Last edited by NewiPhoneDeveloper; 09-30-2008 at 04:17 AM.
NewiPhoneDeveloper is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,669
Threads: 89,155
Posts: 380,381
Top Poster: BrianSlick (7,110)
Welcome to our newest member, jarrettshawn
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:16 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.