static private ArrayList seriesColors = new ArrayList();
public Audiogram(int widthParm, int heightParm)
throws Exception
{
super(widthParm, heightParm);
seriesColors.add(new Color( 0, 0, 255));
// Set the default settings to an industrial audiogram
setType(INDUSTRIAL_AUDIOGRAM);
}
I have some five methods like this, but would like to know whether this code above could cause memory leakage since the seriesColors is static.
If there is a memory leakage, then what is the solution for that?
private static final ColorModel rgbModel = ColorModel.getRGBdefault();
public void setPixels(int x, int y, int w, int h, ColorModel model, int[] pixels, int off, int scansize )
{
if ( model == rgbModel ) {
try {
encodePixelsWrapper( x, y, w, h, pixels, off, scansize );
}
catch ( IOException e ) {
iox = e;
stop();
return;
}
}
else {
int[] rgbPixels = new int[w];
for ( int row = 0; row < h; ++row ) {
int rowOff = off + row * scansize;
for ( int col = 0; col < w; ++col ) {
rgbPixels[col] = model.getRGB( pixels[rowOff + col] );
}
try {
encodePixelsWrapper( x, y + row, w, 1, rgbPixels, 0, w );
}
catch ( IOException e ) {
iox = e;
stop();
return;
}
}
}
}
public static ColorModel getRGBdefault() {
if (RGBdefault == null) {
RGBdefault = new DirectColorModel(32,
0x00ff0000, // Red
0x0000ff00, // Green
0x000000ff, // Blue
0xff000000 // Alpha
);
}
return RGBdefault;
}
Out of these two code which one has serious flaws?