[jdom-interest] SAXBuilder.build out of memory on 138KB data

Sebastian Robertsson sebastian.robertsson at home.se
Tue Apr 1 13:11:26 PST 2003


This problem is caused by an awful memory leak in Java 1.4.1. There are
workarounds, I believe that one of them is described in the FAQ on
www.jdom.org. The memory leak is supposed to be fixed in the next release
from SUN.

/sebastian
  -----Original Message-----
  From: jdom-interest-admin at jdom.org [mailto:jdom-interest-admin at jdom.org]On
Behalf Of Steve Swett
  Sent: den 1 april 2003 23:04
  To: Jdom-Interest at Jdom. Org
  Subject: [jdom-interest] SAXBuilder.build out of memory on 138KB data


  My document build step creates the document based upon the input stream of
an HttpUrlConnection object. The size of the input stream, in this case, is
about 138KB. I get an "out of memory" error.

  When the input stream is about 40KB, this exact same code works just fine.

  Here are the relevant parts of the code:

  package aos320xml;

  import java.io.*;
  import java.net.*;
  import java.util.*;
  import javax.xml.parsers.*; // XML library
  import org.jdom.*; // JDOM library
  import org.jdom.input.SAXBuilder; // JDOM library
  import org.xml.sax.*; // SAX library
  import org.apache.xerces.parsers.*; // XERCES library

  public class AOS320xml {

  public URL url;
  public HttpURLConnection connection;
  SAXBuilder builder = new SAXBuilder();

  ...

  try {

  connection = (HttpURLConnection) url.openConnection();
  connection.setRequestMethod("POST");
  connection.setDoOutput(true);
  PrintWriter out = new PrintWriter(connection.getOutputStream());

  // encode the message
  String myFunction =
"Function="+URLEncoder.encode("GetStudentNames","UTF-8");

  // send the encoded message
  out.print(EncodedMessage);
  out.close();

  // get the XML response

  System.out.println("Before build doc");
  // Following statement causes "out of memory error" when running for
  // all students.
  Document doc = builder.build(connection.getInputStream());
  System.out.println("After build doc");

  ...


  Any ideas why I'm running out of memory? Solution?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20030401/3aaac867/attachment.htm


More information about the jdom-interest mailing list