Hi,
This patch fixes a memory leak in ComponentGraphics (used for drawing
onto GTK surfaces). Due to the ordering of dispose() methods,
CairoGraphics2D.dispose was being called before
ComponentGraphics.disposeSurface - thus disposeSurface returned
prematurely before destroying the surface. Rather than re-ordering the
dispose calls, this patch destroys the surface immediately after it's
used the initialize the cairo context (the cairo context will keep its
own reference to the surface).
One of the rather nasty symptoms of this memory leak was a hanging X
server once the application is exited.
Any chance for this to get in the upcoming release too? =)
Cheers,
Francis
2007-04-09 Francis Kung <[EMAIL PROTECTED]>
PR 31311
* gnu/java/awt/peer/gtk/ComponentGraphics.java
(dispose): Removed method.
(disposeSurface): Removed method.
* gnu_java_awt_peer_gtk_ComponentGraphics.h: Regenerated.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c
(Java_gnu_java_awt_peer_gtk_ComponentGraphics_disposeSurface): Removed.
(Java_gnu_java_awt_peer_gtk_ComponentGraphics_initState): Destroy
surface
after it is used to create a cairo context.
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c,v
retrieving revision 1.18
diff -u -r1.18 gnu_java_awt_peer_gtk_ComponentGraphics.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c 3 Aug 2006 08:08:14 -0000 1.18
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c 9 Apr 2007 21:23:04 -0000
@@ -159,40 +159,13 @@
cr = cairo_create (surface);
g_assert(cr != NULL);
+ cairo_surface_destroy(surface);
gdk_threads_leave();
return PTR_TO_JLONG(cr);
}
-/**
- * Disposes of the surface
- */
-JNIEXPORT void JNICALL
-Java_gnu_java_awt_peer_gtk_ComponentGraphics_disposeSurface
- (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)),
- jlong value)
-{
- struct cairographics2d *gr;
- cairo_surface_t *surface;
-
- gr = JLONG_TO_PTR(struct cairographics2d, value);
-
- if (gr == NULL)
- return;
-
- if (gr->cr == NULL)
- return;
-
- surface = cairo_get_target (gr->cr);
- if (surface != NULL)
- {
- gdk_threads_enter();
- cairo_surface_destroy (surface);
- gdk_threads_leave();
- }
-}
-
JNIEXPORT jlong JNICALL
Java_gnu_java_awt_peer_gtk_ComponentGraphics_initFromVolatile
(JNIEnv *env __attribute__ ((unused)), jobject obj __attribute__ ((unused)),
Index: gnu/java/awt/peer/gtk/ComponentGraphics.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java,v
retrieving revision 1.27
diff -u -r1.27 ComponentGraphics.java
--- gnu/java/awt/peer/gtk/ComponentGraphics.java 4 Apr 2007 19:20:33 -0000 1.27
+++ gnu/java/awt/peer/gtk/ComponentGraphics.java 9 Apr 2007 21:23:04 -0000
@@ -151,21 +151,6 @@
}
/**
- * Destroys the component surface and calls dispose on the cairo
- * graphics2d to destroy any super class resources.
- */
- public void dispose()
- {
- super.dispose();
- disposeSurface(nativePointer);
- }
-
- /**
- * Destroys the component surface.
- */
- private native void disposeSurface(long nativePointer);
-
- /**
* Creates a cairo_t for a volatile image
*/
protected native long initFromVolatile( long pixmapPtr, int width, int height);
Index: include/gnu_java_awt_peer_gtk_ComponentGraphics.h
===================================================================
RCS file: /cvsroot/classpath/classpath/include/gnu_java_awt_peer_gtk_ComponentGraphics.h,v
retrieving revision 1.10
diff -u -r1.10 gnu_java_awt_peer_gtk_ComponentGraphics.h
--- include/gnu_java_awt_peer_gtk_ComponentGraphics.h 21 Aug 2006 23:34:45 -0000 1.10
+++ include/gnu_java_awt_peer_gtk_ComponentGraphics.h 9 Apr 2007 21:23:04 -0000
@@ -11,7 +11,6 @@
#endif
JNIEXPORT jlong JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_initState (JNIEnv *env, jobject, jobject);
-JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_disposeSurface (JNIEnv *env, jobject, jlong);
JNIEXPORT jlong JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_initFromVolatile (JNIEnv *env, jobject, jlong, jint, jint);
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_start_1gdk_1drawing (JNIEnv *env, jobject);
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_end_1gdk_1drawing (JNIEnv *env, jobject);