JVM MEMORY LEAK

1) DataCell.java

public class DataCell

{

public String value = null;

public String href = null;

public String image = null;

public String align = "left";

/**

* Describe constructor here.

*

*/

public DataCell()

{

}

/**

* Describe constructor here.

*

* @param _value a value of type 'String'

* @param _href a value of type 'String'

* @param _image a value of type 'String'

* @param _align a value of type 'String'

*/

public DataCell(String _value, String _href, String _image, String _align)

{

value = _value;

href = _href;

image = _image;

align = _align;

}

/**

* Get the value of value.

* @return Value of value.

*/

public String getValue()

{

return value;

}

/**

* Set the value of value.

* @param v Value to assign to value.

*/

public void setValue(String v)

{

this.value = v;

}

}

2) DataRow.java

public class DataRow

{

public DataCell[] cells;

public booleanisHeader = false;

public booleanisFooter = false;

/**

* Describe constructor here.

*

*/

public DataRow()

{

}

/**

* Describe constructor here.

*

* @param _columns a value of type 'int'

*/

public DataRow(int _columns)

{

cells = new DataCell[_columns];

for (int i = 0; i < _columns; i++)

{

cells = new DataCell();

}

}

}

The above java files are causing JVM Memory leak. I don't know where it is occuring. Please help me in fixing this issue.

[1795 byte] By [JK2004a] at [2007-10-2 23:15:40]
# 1

What do you mean by "causing JVM memory leak"? The code you've shown will allocate DataRows and DataCells, each of which will use up some modest amount of memory. Is it these classes whose instances are "leaking"? Or is it some other class that's leaking? What tools have you used to identify the leak? Which version of the JRE are you using, and what platform (operating system and hardware) are you running on?

Peter.Kessler@Sun.COMa at 2007-7-14 6:30:04 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

There is a bug in your code in the constructor public DataRow(int _columns).

In the for loop of the constructor you have to store the new DataCell into the array declared in the member variable cells.

But you have missed the index i for the cells variable in the for loop

The correct line in the for loop is : cells[ i ] = new DataCell(); instead of cells = new DataCell();

thnks

Bas

genius20_2001a at 2007-7-14 6:30:05 > top of Java-index,Java HotSpot Virtual Machine,Specifications...