G
Guest
Learned Readers:
The following program runs out of memory on my OSF1
platform but seems to work OK on the NT, Solaris, and
Linux hosts I've got access to. Does anyone have any
ideas on what's going on and/or how to work around the
problem? TIA,
% uname -a
OSF1 sys1 V5.1 1885 alpha
% java -version
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition
Fast VM (build 1.4.1-2, native threads, mixed mode, 06/18/2003-17:51)
% java Display
0 free memory: 206817680
1 free memory: 206565520
2 free memory: 206318720
3 free memory: 206071920
4 free memory: 205808736
5 free memory: 205561936
6 free memory: 205315136
7 free memory: 205068336
....
2217 free memory: 2078272
2218 free memory: 1831472
2219 free memory: 1584672
2220 free memory: 1337872
2221 free memory: 1091072
2222 free memory: 827888
2223 free memory: 581088
2224 free memory: 334288
2225 free memory: 87488
2226 free memory: 518520832
2227 free memory: 518274032
2228 free memory: 518010848
2229 free memory: 517764048
.... <lots more mem-grow sequences ommitted>
4290 free memory: 2573488
4291 free memory: 2326688
4292 free memory: 2079728
4293 free memory: 1816544
4294 free memory: 1569744
4295 free memory: 1322944
4296 free memory: 1076144
4297 free memory: 829344
4298 free memory: 582544
4299 free memory: 335744
4300 free memory: 72560
java.lang.OutOfMemoryError
at java.awt.image.DataBufferInt.<init> DataBufferInt.java:41)
at java.awt.image.Raster.createPackedRaster(Raster.java:452)
at
java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1015)
at java.awt.image.BufferedImage.<init>(BufferedImage.java:259)
at Display.<init>(Display.java:97)
at Display.main(Display.java:113)
Note: 200 * 300 = 60000 pixels required for each
Image, and the free memory differences between
displays tends to be 246800. It appears that for
some reason the gc couldn't run when there was only
72560 bytes available for the next Image. Any
ideas why??
Here's the contents of Display.java:
import java.awt.*;
import java.awt.image.*;
import java.awt.geom.*;
import javax.swing.*;
class DisplayPanel extends JPanel
{
private Image curImage = null;
public void setDisplayImage (Image newImage)
{
curImage = newImage;
revalidate ();
repaint ();
}
public void paintComponent (Graphics g)
{
if (curImage == null)
return;
Rectangle r = getBounds ();
g.clearRect (0, 0, r.width, r.height);
g.drawImage (curImage, 0, 0, null);
curImage.flush (); // doesn't help on OSF1
curImage = null; // doesn't help
}
}
class Display extends JFrame
{
static long count = 0L;
static Runtime runtime = Runtime.getRuntime ();
Display () throws Exception // Exceptions from invokeAndWait
{
super ();
final DisplayPanel displayPanel = new DisplayPanel ();
displayPanel.setPreferredSize (new Dimension (200, 300));
getContentPane ().add (displayPanel);
setSize (200, 300);
setVisible (true);
final int rgb[] = new int[200 * 300];
int alpha = 0xff000000;
int red = 150, grn = 150, blu = 150;
int redInc = 2, grnInc = 3, bluInc = 5;
while (true)
{
int val = alpha + (red << 16) + (grn << 8) + blu;
for (int i = 0; i < 200 * 300; i++)
rgb = val;
red += redInc;
blu += bluInc;
grn += grnInc;
if (red > 250 || red < 50) redInc *= -1;
if (grn > 250 || grn < 50) grnInc *= -1;
if (blu > 250 || blu < 50) bluInc *= -1;
final BufferedImage im = new
BufferedImage (200, 300, BufferedImage.TYPE_INT_ARGB);
im.setRGB (0, 0, 200, 300, rgb, 0, 200);
SwingUtilities.invokeAndWait (new Thread ()
{
public void run ()
{
// setPriority (Thread.MIN_PRIORITY); // doesn't help
System.out.println (count++ + " free memory: " +
runtime.freeMemory ());
displayPanel.setDisplayImage (im);
// System.gc (); // doesn't help
// yield (); // doesn't help
}
});
}
}
public static void main (String args[]) throws Exception
{
new Display ();
}
}
The following program runs out of memory on my OSF1
platform but seems to work OK on the NT, Solaris, and
Linux hosts I've got access to. Does anyone have any
ideas on what's going on and/or how to work around the
problem? TIA,
% uname -a
OSF1 sys1 V5.1 1885 alpha
% java -version
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition
Fast VM (build 1.4.1-2, native threads, mixed mode, 06/18/2003-17:51)
% java Display
0 free memory: 206817680
1 free memory: 206565520
2 free memory: 206318720
3 free memory: 206071920
4 free memory: 205808736
5 free memory: 205561936
6 free memory: 205315136
7 free memory: 205068336
....
2217 free memory: 2078272
2218 free memory: 1831472
2219 free memory: 1584672
2220 free memory: 1337872
2221 free memory: 1091072
2222 free memory: 827888
2223 free memory: 581088
2224 free memory: 334288
2225 free memory: 87488
2226 free memory: 518520832
2227 free memory: 518274032
2228 free memory: 518010848
2229 free memory: 517764048
.... <lots more mem-grow sequences ommitted>
4290 free memory: 2573488
4291 free memory: 2326688
4292 free memory: 2079728
4293 free memory: 1816544
4294 free memory: 1569744
4295 free memory: 1322944
4296 free memory: 1076144
4297 free memory: 829344
4298 free memory: 582544
4299 free memory: 335744
4300 free memory: 72560
java.lang.OutOfMemoryError
at java.awt.image.DataBufferInt.<init> DataBufferInt.java:41)
at java.awt.image.Raster.createPackedRaster(Raster.java:452)
at
java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1015)
at java.awt.image.BufferedImage.<init>(BufferedImage.java:259)
at Display.<init>(Display.java:97)
at Display.main(Display.java:113)
Note: 200 * 300 = 60000 pixels required for each
Image, and the free memory differences between
displays tends to be 246800. It appears that for
some reason the gc couldn't run when there was only
72560 bytes available for the next Image. Any
ideas why??
Here's the contents of Display.java:
import java.awt.*;
import java.awt.image.*;
import java.awt.geom.*;
import javax.swing.*;
class DisplayPanel extends JPanel
{
private Image curImage = null;
public void setDisplayImage (Image newImage)
{
curImage = newImage;
revalidate ();
repaint ();
}
public void paintComponent (Graphics g)
{
if (curImage == null)
return;
Rectangle r = getBounds ();
g.clearRect (0, 0, r.width, r.height);
g.drawImage (curImage, 0, 0, null);
curImage.flush (); // doesn't help on OSF1
curImage = null; // doesn't help
}
}
class Display extends JFrame
{
static long count = 0L;
static Runtime runtime = Runtime.getRuntime ();
Display () throws Exception // Exceptions from invokeAndWait
{
super ();
final DisplayPanel displayPanel = new DisplayPanel ();
displayPanel.setPreferredSize (new Dimension (200, 300));
getContentPane ().add (displayPanel);
setSize (200, 300);
setVisible (true);
final int rgb[] = new int[200 * 300];
int alpha = 0xff000000;
int red = 150, grn = 150, blu = 150;
int redInc = 2, grnInc = 3, bluInc = 5;
while (true)
{
int val = alpha + (red << 16) + (grn << 8) + blu;
for (int i = 0; i < 200 * 300; i++)
rgb = val;
red += redInc;
blu += bluInc;
grn += grnInc;
if (red > 250 || red < 50) redInc *= -1;
if (grn > 250 || grn < 50) grnInc *= -1;
if (blu > 250 || blu < 50) bluInc *= -1;
final BufferedImage im = new
BufferedImage (200, 300, BufferedImage.TYPE_INT_ARGB);
im.setRGB (0, 0, 200, 300, rgb, 0, 200);
SwingUtilities.invokeAndWait (new Thread ()
{
public void run ()
{
// setPriority (Thread.MIN_PRIORITY); // doesn't help
System.out.println (count++ + " free memory: " +
runtime.freeMemory ());
displayPanel.setDisplayImage (im);
// System.gc (); // doesn't help
// yield (); // doesn't help
}
});
}
}
public static void main (String args[]) throws Exception
{
new Display ();
}
}