8036917: [macosx] Native memory leaks.
authorpchelko
Thu, 08 May 2014 16:50:42 +0400
changeset 24554 55edf9459457
parent 24553 6c9c0f5b07e0
child 24555 42926c558bc8
8036917: [macosx] Native memory leaks. Reviewed-by: serb, azvegint
jdk/src/macosx/native/sun/awt/CImage.m
--- a/jdk/src/macosx/native/sun/awt/CImage.m	Thu May 08 11:46:03 2014 +0200
+++ b/jdk/src/macosx/native/sun/awt/CImage.m	Thu May 08 16:50:42 2014 +0400
@@ -76,17 +76,17 @@
 
 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 @@
     
     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 @@
         (*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 @@
 
     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 @@
 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 @@
 
     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];