<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META content="MSHTML 5.00.2614.3500" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>It seems to me that it is very difficult
for garbage collector (gc) to collect jdom document and element objects.
Here is a test program:</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>import java.io.*;<BR>import org.jdom.*;<BR>import
org.jdom.input.*;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>public class XMLMemoryTest extends Object
{</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> public XMLMemoryTest(String
file) {<BR>
loadXML(file);<BR> }</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> private void loadXML(String
file) {<BR> try
{<BR>
SAXBuilder builder = new
SAXBuilder(false);<BR>
Document doc = builder.build(new
File(file));<BR>
Element root =
doc.getRootElement();<BR>
root =
null;<BR> doc
= null;<BR>
file =
null;<BR>
gc();<BR>
}<BR> catch(Exception e)
{<BR> e.printStackTrace();<BR>
}<BR> }</FONT></DIV>
<DIV><FONT face=Arial size=2> /** This method is
from the book Java Platform Performace by Wilson, S & Kesselman, J.
*/</FONT></DIV>
<DIV><FONT face=Arial size=2> private void gc()
{<BR> try
{<BR>
System.gc();<BR>
Thread.currentThread().sleep(100);<BR>
System.runFinalization();<BR>
Thread.currentThread().sleep(100);<BR>
System.gc();<BR>
Thread.currentThread().sleep(100);<BR>
System.runFinalization();<BR>
Thread.currentThread().sleep(100);<BR>
}<BR> catch(Exception e)
{<BR>
e.printStackTrace();<BR>
}<BR> }<BR>}</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>import java.io.*;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>public class XMLMemoryTestRunner extends Object
{</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> public static void main(String
args[]) {<BR> if (args.length < 1)
{<BR>
System.out.println("Usage java test.XMLMemoryTest
xmlfile");<BR>
return;<BR>
}<BR> memoryInfo("Before loading:
");<BR> XMLMemoryTest test = new
XMLMemoryTest(args[0]);<BR> test =
null;<BR> memoryInfo("After loading:
");<BR> try
{<BR>
BufferedReader reader = new BufferedReader(new
InputStreamReader(System.in));<BR>
String line =
null;<BR>
while (true)
{<BR>
line =
reader.readLine();<BR>
if (line.equalsIgnoreCase("quit"))
break;<BR>
if (line.equalsIgnoreCase("check")) memoryInfo("Memory:
");<BR>
}<BR>
}<BR> catch(IOException e)
{<BR>
e.printStackTrace();<BR>
}<BR> }<BR> <BR> protected
static void memoryInfo(String label)
{<BR> long total =
Runtime.getRuntime().totalMemory();<BR>
long free =
Runtime.getRuntime().freeMemory();<BR>
System.out.println(label + " total " + total + " usage " + (total -
free));<BR> }</FONT></DIV>
<DIV><FONT face=Arial size=2>}</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>Compile them and run
XMLMemoryTestRunner.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>I tested with an 1M XML file, the memory
about 8000M could not be released. </FONT><FONT face=Arial size=2>I am wondering
if there are any problems with my codes?</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>Thanks.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>Guanming</FONT></DIV>
<DIV> </DIV></BODY></HTML>