memory leak? amd 64 bit using 1.4.2_03 program runs fine on other computers
I have a program that runs fine on a red hat linux desktop and a pentium 1.6ghz xp pro laptop but on my amd 64 bit 3400+ xp pro desktop after ~20 seconds it slows to a crawl. i was originally using j2sdk1.4.2_04 but noticed this was not available for download anymore so i switched to j2sdk1.4.2_03 but have the same problem. my laptop is using j2sdk1.4.2_03. im not sure what the red hat linux machine is using. this is a starfield simulator and when it starts to slow all the stars turn gray and its like the drawLine is not working right either. anyone have any ideas? code is below
import java.awt.*;
import java.awt.event.WindowListener;
import java.awt.event.WindowEvent;
import java.util.*;
import javax.swing.*;
import java.io.*;
class StarfieldWindowListener implements WindowListener
{
public void windowActivated( WindowEvent e ) {}
public void windowClosed( WindowEvent e ) {}
public void windowClosing( WindowEvent e )
{
System.exit(0);
}
public void windowDeactivated( WindowEvent e ) {}
public void windowDeiconified( WindowEvent e ) {}
public void windowIconified( WindowEvent e ) {}
public void windowOpened( WindowEvent e ) {}
}
public class StarfieldSimulator
{
public static void main (String args[])
{
JFrame frame = new JFrame ("Starfield Simulator");
frame.getContentPane ().setLayout (new BorderLayout ());
if (args.length == 0) frame.getContentPane ().add (new Starfield (500));
else frame.getContentPane ().add (new Starfield (Integer.parseInt (args[0])));
frame.addWindowListener(new StarfieldWindowListener());
frame.setSize (1024, 768);
frame.show ();
}
}
class Point3D
{
public doublex, y, z;
public floatr, g, b;
public Colorc;
public Point3D (double x, double y, double z)
{
Random random = new Random ();
this.x = x;
this.y = y;
this.z = z;
r = random.nextFloat();
g = random.nextFloat();
b = random.nextFloat();
c = new Color( r, g, b );
}
}
class Starfield extends JComponent
{
protected boolean first;
protected Point3D points[][];
protected Random random;
private inttrail = 20;
private double rot = .0005, co = Math.cos( rot ), si = Math.sin( rot );
public Starfield (int numPoints)
{
//RepaintManager repaintManager = RepaintManager.currentManager(this); repaintManager.setDoubleBufferingEnabled(false);
first = true;
random = new Random ();
points = new Point3D[numPoints][trail];
for( int y = 0; y < numPoints; ++y )
{
for( int x = 1; x < trail; ++x )
{
points[y][x] = new Point3D( 0, 0, 0 );
}
}
for (int index = 0; index < numPoints; index++)
{
points[index][0] = new Point3D ((random.nextDouble () - 0.5) * 2.0, (random.nextDouble () - 0.5) * 2.0, (random.nextDouble () - 0.5) * 2.0);
}
}
public void paint (Graphics g)
{
//DebugGraphicsg = new DebugGraphics(g1);
int i;
int halfWidth = getWidth () / 2;
int halfHeight = getHeight () / 2;
g.setColor (Color.black);
g.fillRect (0, 0, getWidth (), getHeight ());
int pointsLength = points.length;
for (int index = 0; index < pointsLength; index++)
{
for( i = trail - 1; i >= 1; --i )
{
points[index] = points[index][i - 1];
}
if( points[index][0].z <= 0.0 )
{
while (points[index][0].z <= 0.0) points[index][0] = new Point3D ((random.nextDouble () - 0.5) * 2.0, (random.nextDouble () - 0.5) * 2.0, (random.nextDouble () - 0.5) * 2.0);
points[index][0].r = random.nextFloat();
points[index][0].g = random.nextFloat();
points[index][0].b = random.nextFloat();
for( i = 1; i < trail; ++i )
{
points[index].x =points[index].y = points[index].z = 0;
}
}
g.setColor (points[index][0].c);
for( i = 0; i < trail; ++i )
{
points[index].x = points[index].x * co - points[index].y * si;
points[index].y = points[index].y * co + points[index].x * si;
}
int sx1, sy1, sx2, sy2;
sx1 = (int) ((points[index][0].x * halfWidth) / ((points[index][0].z) * 10.0)) + halfWidth;
sy1 = (int) ((points[index][0].y * halfHeight) / ((points[index][0].z) * 10.0)) + halfHeight;
if( points[index][(trail - 1)].z == 0 )
{
g.drawRect( sx1, sy1, 1, 1 );
}
else
{
sx2 = (int) ((points[index][(trail - 1)].x * halfWidth) / ((points[index][(trail - 1)].z + .0005 * (trail - 1)) * 10.0)) + halfWidth;
sy2 = (int) ((points[index][(trail - 1)].y * halfHeight) / ((points[index][(trail - 1)].z + .0005 * (trail - 1)) * 10.0)) + halfHeight;
g.drawLine( sx1, sy1, sx2, sy2 );
}
points[index][0].r = (float) Math.min ( points[index][0].r + .00005, 1.0 );
points[index][0].g = (float) Math.min ( points[index][0].g + .00005, 1.0 );
points[index][0].b = (float) Math.min ( points[index][0].b + .00005, 1.0 );
points[index][0].c = new Color( points[index][0].r, points[index][0].g, points[index][0].b );
points[index][0].z -= 0.0025;
}
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
repaint();
}
}

