У меня есть простой метод выбора фотографий:
- (IBAction)photoTapped:(id)sender {
// If in editing state, then display an image picker; if not, create and push a photo view controller.
if (self.editing) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
// Set source to the Photo Library
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// iPad-specific interface here
self.popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
self.popover.delegate =self;
[self.popover presentPopoverFromRect:CGRectMake(self.parentViewController.view.frame.size.width, self.parentViewController.view.frame.size.height, 0.0, 0.0)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
else
{
// iPhone and iPod touch interface here
if ([self respondsToSelector:@selector(presentingViewController)])
{
[[self parentViewController] presentViewController:imagePicker animated:YES completion:nil ];
}
else
{
[[self parentViewController] presentModalViewController:imagePicker animated:YES];
}
}
imagePicker = nil;
}
else {
NSLog(@"UIImagePickerController source doesn't support");
}
//[imagePicker release];
} else {
PhotoViewController *photoViewController = [[PhotoViewController alloc] init];
photoViewController.hidesBottomBarWhenPushed = YES;
photoViewController.remember = remember;
[self.navigationController pushViewController:photoViewController animated:YES];
//[photoViewController release];
photoViewController = nil;
}
}
and didfinish method:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editingInfo {
NSLog(@"Begin didFinishPickingImage in rememberdetailview controller");
// commented out thumbnail code completely to understand memory leak
//but even then it leaks
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
[self.photoButton setImage:remember.thumbnail forState:UIControlStateNormal];
[self.popover dismissPopoverAnimated:YES];
}
else {
if ([self respondsToSelector:@selector(presentingViewController)]) {
[[self parentViewController] dismissViewControllerAnimated:YES completion:nil];
} else {
[[self parentViewController] dismissModalViewControllerAnimated:YES];
}
}
}
, как вы можете видеть из приведенного выше кода, я делаю простые базовые вещи!Мои приложения отлично работают с выбором фото / изменением размера / уменьшением изображения и т. Д., Но даже после комментирования кода изменения размера / эскиза у меня возникает проблема утечки памяти в инструментах, как показано ниже.
Можете ли вы пролить свет на эту утечку памяти?Я использую ARC!