Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-24206] iOS: Fix image-picker memory-leak, fix 0.5 delay when closing the dialog #8676

Merged
merged 2 commits into from
Dec 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 5 additions & 9 deletions iphone/Classes/MediaModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -1370,17 +1370,13 @@ -(void)destroyPicker

-(void)dispatchCallback:(NSArray*)args
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *type = [args objectAtIndex:0];
id object = [args objectAtIndex:1];
id listener = [args objectAtIndex:2];
// we have to give our modal picker view time to
// dismiss with animation or if you do anything in a callback that
// attempt to also touch a modal controller, you'll get into deep doodoo
// wait for the picker to dismiss with animation
[NSThread sleepForTimeInterval:0.5];
[self _fireEventToListener:type withObject:object listener:listener thisObject:nil];
[pool release];

TiThreadPerformOnMainThread(^{
[self _fireEventToListener:type withObject:object listener:listener thisObject:nil];
}, YES);
}

-(void)sendPickerError:(int)code
Expand Down Expand Up @@ -2050,7 +2046,7 @@ - (void)imagePickerController:(UIImagePickerController *)picker_ didFinishPickin
}

if (resultImage == nil) {
resultImage = (editedImage != nil) ? [TiUtils adjustRotation:editedImage] : [TiUtils adjustRotation:originalImage];
resultImage = [TiUtils adjustRotation:editedImage ?: originalImage];
}

media = [[[TiBlob alloc] _initWithPageContext:[self pageContext]] autorelease];
Expand Down
7 changes: 4 additions & 3 deletions iphone/Classes/TiUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,9 @@ +(UIImage*)toImage:(id)object proxy:(TiProxy*)proxy
return image;
//Note: If url is a nonimmediate image, this returns nil.
}
+(UIImage *)adjustRotation:(UIImage *) image {


+(UIImage *)adjustRotation:(UIImage *) image
{
CGImageRef imgRef = image.CGImage;
CGFloat width = CGImageGetWidth(imgRef);
CGFloat height = CGImageGetHeight(imgRef);
Expand Down Expand Up @@ -785,7 +786,7 @@ +(UIImage *)adjustRotation:(UIImage *) image {
UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return imageCopy;
return [imageCopy autorelease];
}

+(NSURL*)checkFor2XImage:(NSURL*)url
Expand Down