Eli,

Another thing is to make sure to always "release" large resources as soon as possible and always before reassigning a new allocation to it. For instance if you had something like this:
myResource = new LargeResource();
....
myResource = new LargeResource();
  
It really should be written as:
myResource = new LargeResource();
...
myResource = null; // let the garbage collector cleanup
myResource = new LargeResource();
  
Hope this helps:

Michael

P.S.
You can easily test this for yourself with a simple class. First, find a number for the array that just causes the array allocation to fail. On my Sun with Java 1.4.2 it was around 7500000 (7400000 did not fail) with the default memory model. Then uncomment the preceding array = null; assignment and notice that it will not run out of memory. The reason is that array does not become a candidate for garbage collection until after the allocation and assignment unless you first assign it to null. This is not a problem for small classes but for bit ones it is really critical.
public class Testit
    {
    private int[] array;
    public Testit()
        {
        array = null;
        }

    public void doit()
        {
        // array = null;
        array = new int[7300000];
        }

    static public void main(String[] args)
        {
        Testit testit = new Testit();

        testit.doit();
        testit.doit();
        }
    }
Dmitri Trembovetski wrote:
  Hi Eli,

On Tue, Nov 18, 2003 at 04:07:24PM -0800, eli curtz wrote:
 > I'm working on a suite of simulation software which does a lot of drawing
 > between BufferedImages and I have run into a memory issue with
 > Graphics2D.drawImage(Image, AffineTransform, ImageObserver), where
 > AffineTransform includes a rotation.
 >
 > According to J-Sprint 99%+ of my memory allocation is occuring when
 > DrawImage.transformImage calls
 > IntegerInterleavedRaster.createCompatibleWritableRaster(int, int). This is
 > causing massive thrashing in the garbage collector and horrible stuttering
 > in my graphics.
 >
 > Anybody have any advice on how to eliminate this? The source and destination
 > images are identical format. I'm not even sure what it's doing - creating a
 > temporary raster to draw the rotated image into?

  That's exactly what it's doing.

  What java release are you using?
  We've improved our memory usage pattern somewhat in 1.4.1, I
  believe, by using our own thread to dispose of Java2D-generated
  garbage.

  Thank you,
    Dmitri

 >
 > thanks,
 > eli curtz
 >
 > [EMAIL PROTECTED]
 >
 > ===========================================================================
 > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
 > of the message "signoff JAVA2D-INTEREST".  For general help, send email to
 > [EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
  
=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA2D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to