Hi,
While looking for memory leaks in my application using a profiler, I just find out that the Graphics class was one of the problem !
The methods Graphics.hitClip() and Graphics.getClipBounds® are creating a huge amount of Rectangle objects. These methods are called from the paintchildren() of JComponent.
The distressing part is the comment I found in the Graphics class source code in the hitClip() method :
public boolean hitClip(int x, int y, int width, int height)
{
// Note, this implementation is not very efficient.
// Subclasses should override this method and calculate
// the results more directly.
Rectangle clipRect = getClipBounds();
if (clipRect == null) {
return true;
}
return clipRect.intersects(x, y, width, height);
}
How do we subclass the Graphics class ?
The only information I found so far was the following class hierarchy :
[]public java.lang.Object
[]public abstract java.awt.Graphics
[]public abstract java.awt.Graphics2D
[]public abstract sun.java2d.SunGraphics2D
[*]public sun.awt.windows.WGraphics
There are way too many abstract methods to implement in the Graphics class…
My Goal is to optimize the Graphics class for less Rectangle object creation ? Any ideas ?
Thanks,
Philippe