You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by de...@apache.org on 2001/04/19 23:30:50 UTC
cvs commit: xml-batik/sources/org/apache/batik/gvt/filter GraphicsNodeRed8Bit.java
deweese 01/04/19 14:30:50
Modified: sources/org/apache/batik/ext/awt BufferedImageHintKey.java
sources/org/apache/batik/ext/awt/image GraphicsUtil.java
sources/org/apache/batik/ext/awt/image/rendered TileRed.java
sources/org/apache/batik/gvt/filter GraphicsNodeRed8Bit.java
Log:
BufferedImageHint now uses a Weak Reference to the destination
BufferedImage.
This solves the memory leak Thierry noticed. The GraphicsNodeRable's
hold a reference to the hints in the GraphicsNode, which means that in
the past they would keep the destination BufferedImage alive long
after it should have been GC'd.
I can now traverse the entire test document without stressing the
default memory partition at all.
Revision Changes Path
1.2 +10 -1 xml-batik/sources/org/apache/batik/ext/awt/BufferedImageHintKey.java
Index: BufferedImageHintKey.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/ext/awt/BufferedImageHintKey.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BufferedImageHintKey.java 2001/02/03 16:26:05 1.1
+++ BufferedImageHintKey.java 2001/04/19 21:30:49 1.2
@@ -8,6 +8,8 @@
package org.apache.batik.ext.awt;
+import java.lang.ref.Reference;
+
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
@@ -16,13 +18,20 @@
* <code>GraphicsNode</code>.
*
* @author <a href="mailto:cjolif@ilog.fr">Christophe Jolif</a>
- * @version $Id: BufferedImageHintKey.java,v 1.1 2001/02/03 16:26:05 deweese Exp $
+ * @version $Id: BufferedImageHintKey.java,v 1.2 2001/04/19 21:30:49 deweese Exp $
*/
final class BufferedImageHintKey extends RenderingHints.Key {
BufferedImageHintKey() {
super(1001);
}
public boolean isCompatibleValue(Object val) {
+ if (val == null)
+ return true;
+
+ if (!(val instanceof Reference))
+ return false;
+ Reference ref = (Reference)val;
+ val = ref.get();
if (val == null)
return true;
if (val instanceof BufferedImage)
1.12 +9 -4 xml-batik/sources/org/apache/batik/ext/awt/image/GraphicsUtil.java
Index: GraphicsUtil.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/GraphicsUtil.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- GraphicsUtil.java 2001/03/26 21:27:29 1.11
+++ GraphicsUtil.java 2001/04/19 21:30:49 1.12
@@ -8,6 +8,9 @@
package org.apache.batik.ext.awt.image;
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
+
import java.awt.color.ColorSpace;
import java.awt.Color;
@@ -65,7 +68,7 @@
* implementations.
*
* @author <a href="mailto:Thomas.DeWeeese@Kodak.com">Thomas DeWeese</a>
- * @version $Id: GraphicsUtil.java,v 1.11 2001/03/26 21:27:29 deweese Exp $
+ * @version $Id: GraphicsUtil.java,v 1.12 2001/04/19 21:30:49 deweese Exp $
*/
public class GraphicsUtil {
@@ -448,7 +451,8 @@
Graphics2D g2d = bi.createGraphics();
if (hints != null)
g2d.addRenderingHints(hints);
- g2d.setRenderingHint(RenderingHintsKeyExt.KEY_BUFFERED_IMAGE, bi);
+ g2d.setRenderingHint(RenderingHintsKeyExt.KEY_BUFFERED_IMAGE,
+ new WeakReference(bi));
g2d.clip(new Rectangle(0, 0, bi.getWidth(), bi.getHeight()));
return g2d;
}
@@ -456,7 +460,8 @@
public static Graphics2D createGraphics(BufferedImage bi) {
Graphics2D g2d = bi.createGraphics();
- g2d.setRenderingHint(RenderingHintsKeyExt.KEY_BUFFERED_IMAGE, bi);
+ g2d.setRenderingHint(RenderingHintsKeyExt.KEY_BUFFERED_IMAGE,
+ new WeakReference(bi));
g2d.clip(new Rectangle(0, 0, bi.getWidth(), bi.getHeight()));
return g2d;
}
@@ -468,7 +473,7 @@
Object o = g2d.getRenderingHint
(RenderingHintsKeyExt.KEY_BUFFERED_IMAGE);
if (o != null)
- return (BufferedImage)o;
+ return (BufferedImage)(((Reference)o).get());
// Check if this is a BufferedImage G2d if so throw an error...
GraphicsConfiguration gc = g2d.getDeviceConfiguration();
1.5 +11 -4 xml-batik/sources/org/apache/batik/ext/awt/image/rendered/TileRed.java
Index: TileRed.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/rendered/TileRed.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TileRed.java 2001/02/23 14:59:59 1.4
+++ TileRed.java 2001/04/19 21:30:49 1.5
@@ -37,7 +37,7 @@
* left corner of the tiled region.
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: TileRed.java,v 1.4 2001/02/23 14:59:59 deweese Exp $
+ * @version $Id: TileRed.java,v 1.5 2001/04/19 21:30:49 deweese Exp $
*/
public class TileRed extends AbstractRed implements TileGenerator {
static final AffineTransform IDENTITY = new AffineTransform();
@@ -92,7 +92,6 @@
// org.apache.batik.test.gvt.ImageDisplay.showImage("Tile: ", tile);
this.tiledRegion = tiledRegion;
- this.tile = tile;
this.xStep = xStep;
this.yStep = yStep;
this.hints = hints;
@@ -107,7 +106,6 @@
raster = Raster.createWritableRaster
(sm, new Point(tile.getMinX(), tile.getMinY()));
}
-
// Initialize our base class We set our bounds be we will
// respond with data for any area we cover. This is needed
@@ -120,9 +118,12 @@
if (raster != null) {
fillRasterFrom(raster, tile);
+ this.tile = null; // don't need it (It's in the raster).
}
- else
+ else {
+ this.tile = tile;
tiles = TileCache.getTileMap(this);
+ }
}
public WritableRaster copyData(WritableRaster wr) {
@@ -165,6 +166,12 @@
int tx = tileGridXOff+x*tileWidth;
int ty = tileGridYOff+y*tileHeight;
+ if (raster!=null) {
+ // We have a Single raster that we translate where needed
+ // position. So just offest appropriately.
+ return raster.createTranslatedChild(tx, ty);
+ }
+
Point pt = new Point(tx, ty);
WritableRaster wr = Raster.createWritableRaster(sm, pt);
fillRasterFrom(wr, tile);
1.6 +2 -6 xml-batik/sources/org/apache/batik/gvt/filter/GraphicsNodeRed8Bit.java
Index: GraphicsNodeRed8Bit.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/filter/GraphicsNodeRed8Bit.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- GraphicsNodeRed8Bit.java 2001/03/05 22:07:09 1.5
+++ GraphicsNodeRed8Bit.java 2001/04/19 21:30:49 1.6
@@ -11,9 +11,6 @@
import org.apache.batik.ext.awt.image.GraphicsUtil;
import org.apache.batik.ext.awt.image.rendered.AbstractTiledRed;
import org.apache.batik.ext.awt.image.rendered.CachableRed;
-import org.apache.batik.ext.awt.image.rendered.TileGenerator;
-import org.apache.batik.ext.awt.image.rendered.TileStore;
-import org.apache.batik.ext.awt.image.rendered.TileCache;
import java.awt.AlphaComposite;
import java.awt.Rectangle;
@@ -36,10 +33,9 @@
* GraphicsNode on demand for tiles.
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
- * @version $Id: GraphicsNodeRed8Bit.java,v 1.5 2001/03/05 22:07:09 vhardy Exp $
+ * @version $Id: GraphicsNodeRed8Bit.java,v 1.6 2001/04/19 21:30:49 deweese Exp $
*/
-public class GraphicsNodeRed8Bit extends AbstractTiledRed
- implements TileGenerator {
+public class GraphicsNodeRed8Bit extends AbstractTiledRed {
/**
* GraphicsNode this image can render
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org