iOS: fix memory leak
This commit is contained in:
parent
37197a8f45
commit
e55b64158c
@ -26,14 +26,14 @@ - (void)getImageInfo:(NSDictionary *)resource withPromise:(DoricPromise *)promis
|
||||
DoricResource *doricResource = [self.doricContext.driver.registry.loaderManager load:resource withContext:self.doricContext];
|
||||
if (doricResource != nil) {
|
||||
DoricAsyncResult *asyncResult = [doricResource fetch];
|
||||
[asyncResult setResultCallback:^(id _Nonnull result) {
|
||||
[asyncResult setResultCallback:^(id _Nonnull result) {
|
||||
UIImage *image = [UIImage imageWithData:result];
|
||||
[promise resolve:@{
|
||||
@"width": @(image.size.width),
|
||||
@"height": @(image.size.height)
|
||||
@"width": @(image.size.width),
|
||||
@"height": @(image.size.height)
|
||||
}];
|
||||
}];
|
||||
[asyncResult setExceptionCallback:^(NSException * _Nonnull e) {
|
||||
[asyncResult setExceptionCallback:^(NSException *_Nonnull e) {
|
||||
DoricLog(@"Cannot load resource %s, %s", resource.description, e.description);
|
||||
}];
|
||||
} else {
|
||||
@ -46,7 +46,7 @@ - (void)decodeToPixels:(NSDictionary *)resource withPromise:(DoricPromise *)prom
|
||||
DoricResource *doricResource = [self.doricContext.driver.registry.loaderManager load:resource withContext:self.doricContext];
|
||||
if (doricResource != nil) {
|
||||
DoricAsyncResult *asyncResult = [doricResource fetch];
|
||||
[asyncResult setResultCallback:^(id _Nonnull result) {
|
||||
[asyncResult setResultCallback:^(id _Nonnull result) {
|
||||
UIImage *image = [UIImage imageWithData:result];
|
||||
|
||||
CGImageRef imageRef = image.CGImage;
|
||||
@ -65,11 +65,10 @@ - (void)decodeToPixels:(NSDictionary *)resource withPromise:(DoricPromise *)prom
|
||||
CGColorSpaceRelease(colorspace);
|
||||
CGContextRelease(context);
|
||||
|
||||
NSData* data = [NSData dataWithBytes:(const void *)imageBytes length:sizeof(unsigned char) * iWidth * iHeight * iBytesPerPixel];
|
||||
|
||||
NSData *data = [NSData dataWithBytesNoCopy:(void *) imageBytes length:sizeof(unsigned char) * iWidth * iHeight * iBytesPerPixel freeWhenDone:YES];
|
||||
[promise resolve:data];
|
||||
}];
|
||||
[asyncResult setExceptionCallback:^(NSException * _Nonnull e) {
|
||||
[asyncResult setExceptionCallback:^(NSException *_Nonnull e) {
|
||||
DoricLog(@"Cannot load resource %s, %s", resource.description, e.description);
|
||||
}];
|
||||
} else {
|
||||
|
@ -761,7 +761,7 @@ - (NSData *)getImagePixels {
|
||||
CGColorSpaceRelease(colorSpace);
|
||||
CGContextRelease(contextRef);
|
||||
|
||||
return [[NSData alloc] initWithBytesNoCopy:imageData length:width * height * bytesPerPixel];
|
||||
return [[NSData alloc] initWithBytesNoCopy:imageData length:width * height * bytesPerPixel freeWhenDone:YES];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
|
Reference in New Issue
Block a user