8036917: [macosx] Native memory leaks

Reviewed-by: serb, azvegint
This commit is contained in:
Petr Pchelko 2014-05-08 16:50:42 +04:00
parent 535c74a38e
commit 1ec8e7aa8a

View File

@ -76,17 +76,17 @@ static void CImage_CopyNSImageIntoArray
static NSBitmapImageRep* CImage_CreateImageRep(JNIEnv *env, jintArray buffer, jint width, jint height)
{
NSBitmapImageRep* imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:width
pixelsHigh:height
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bitmapFormat:NSAlphaFirstBitmapFormat
bytesPerRow:width*4 // TODO: use explicit scanStride
bitsPerPixel:32];
NSBitmapImageRep* imageRep = [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:width
pixelsHigh:height
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bitmapFormat:NSAlphaFirstBitmapFormat
bytesPerRow:width*4 // TODO: use explicit scanStride
bitsPerPixel:32] autorelease];
jint *imgData = (jint *)[imageRep bitmapData];
if (imgData == NULL) return 0L;
@ -115,9 +115,8 @@ JNF_COCOA_ENTER(env);
NSBitmapImageRep* imageRep = CImage_CreateImageRep(env, buffer, width, height);
if (imageRep) {
NSImage *nsImage = [[[NSImage alloc] initWithSize:NSMakeSize(width, height)] retain];
NSImage *nsImage = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
[nsImage addRepresentation:imageRep];
[imageRep release];
result = ptr_to_jlong(nsImage);
}
@ -160,7 +159,7 @@ JNF_COCOA_ENTER(env);
(*env)->ReleaseIntArrayElements(env, widths, ws, JNI_ABORT);
}
if ([reps count]) {
NSImage *nsImage = [[[NSImage alloc] initWithSize:NSMakeSize(0, 0)] retain];
NSImage *nsImage = [[NSImage alloc] initWithSize:NSMakeSize(0, 0)];
[nsImage addRepresentations: reps];
result = ptr_to_jlong(nsImage);
}
@ -184,7 +183,7 @@ JNF_COCOA_ENTER(env);
IconRef iconRef;
if (noErr == GetIconRef(kOnSystemDisk, kSystemIconsCreator, selector, &iconRef)) {
image = [[[NSImage alloc] initWithIconRef:iconRef] retain];
image = [[NSImage alloc] initWithIconRef:iconRef];
ReleaseIconRef(iconRef);
}
@ -206,7 +205,7 @@ JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromFile
JNF_COCOA_ENTER(env);
NSString *path = JNFNormalizedNSStringForPath(env, file);
image = [[[NSImage alloc] initByReferencingFile:path] retain];
image = [[NSImage alloc] initByReferencingFile:path];
JNF_COCOA_EXIT(env);
@ -435,7 +434,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_lwawt_macosx_CImage_nativeGetPlatformImage
JNF_COCOA_ENTER(env);
NSBitmapImageRep* imageRep = [CImage_CreateImageRep(env, buffer, width, height) autorelease];
NSBitmapImageRep* imageRep = CImage_CreateImageRep(env, buffer, width, height);
if (imageRep) {
NSData *tiffImage = [imageRep TIFFRepresentation];
jsize tiffSize = (jsize)[tiffImage length];