Bug 315

Summary: Memory Leak with Overlay
Product: [JogAmp] Jogl Reporter: Sven Gothel <sgothel>
Component: coreAssignee: Sven Gothel <sgothel>
Severity: normal    
Priority: P3    
Version: 1   
Hardware: All   
OS: all   
Type: DEFECT SCM Refs:
Workaround: ---

Description Sven Gothel 2010-03-24 07:50:48 CET

---- Reported by jlhider 2007-09-03 13:55:30 ----

When using an Overlay object to create a graphics context to paint with Java2D, 
calling dispose on the graphics context is not enough - the underlying 
TextureRenderer dispose method should also be invoked. However, the Overlay 
class does not expose a mechanism to invoke the TextureRenderer dispose. The 
result is a rapid consumption of memory.
The following snippet shows the basic GLEventListener I used to render the 
overlay in a loop cycle - no actual painting is necessary to consume memory.

public CustomGLEventListener implements GLEventListener {

public void display(GLAutoDrawable drawable) {
	Overlay overlay = new Overlay(drawable);
	Graphics2D g = overlay.createGraphics();
	// paint(g); // painting goes here
	//overlay.dispose(); // Recommended addition

public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, 
boolean deviceChanged) { /* NOOP */ }
public void init(GLAutoDrawable drawable) { /* NOOP */ }
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int 
height) { /* NOOP */ }


Adding the following method to the com.sun.opengl.util.j2d.Overlay class  and 
invoking it when the overlay is no longer needed appears to resolve the memory 
consumption problem:
public void dispose() {

I expect subsequent calls to the overlay object after dispose is invoked will 
throw a NullPointerException (such as if createGraphics were to be called).

---- Additional Comments From kbr 2007-09-17 15:39:18 ----

This isn't the recommended usage style for the Overlay. You're supposed to
create it once in your init() method and use it many times in your display
callback. See demos.j2d.TestOverlay in the jogl-demos workspace.

I agree that for completeness a dispose() call should probably be added, but
this is really more a bug in the application and not in JOGL.

---- Additional Comments From jlhider 2007-09-18 22:52:58 ----

Understood. The example was simply to demonstrate the condition where if you 
stop using an overlay (and discard it), there is a risk of creeping memory 
consumption. It would not likely be noticed during quick development test runs 
or for short running apps, but could reveal itself in long runs of dynamic apps 
(or in a brutal case such as the example). If during some point in the 
application I want to use one or more overlays (for whatever reason), I should 
be able to release them during the spans of time that they are not needed. 

That's all.

--- Bug imported by sgothel@jausoft.com 2010-03-24 07:50 EDT  ---

This bug was previously known as _bug_ 315 at https://jogl.dev.java.net/bugs/show_bug.cgi?id=315

Bug has invalid status, setting status to "NEW".
   Previous status was "STARTED".