Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Why the memory is not released?

Michael ShapiraApr 18 2019

Hi. I am using Java 8 update 101 64 bit

I wrote a simple program that adds dummy data into XMLWriter. After execution of the program I expect the memory to be released. But it is not. It remains.

Can you please advice?

public static void writeSimpleElement(String elementName,

            String elementValue,

            XMLStreamWriter writer) throws XMLStreamException

{

writer.writeStartElement(elementName);

writer.writeCharacters(elementValue);

writer.writeEndElement();

}

public static void main(String[] args) throws PSException, XMLStreamException, IOException {

XMLOutputFactory factory = XMLOutputFactory.newInstance();

ByteArrayOutputStream o = new ByteArrayOutputStream();

GZIPOutputStream outputStreamZip = new GZIPOutputStream(o);

       

XMLStreamWriter writer = factory.createXMLStreamWriter(outputStreamZip, "UTF-8");

writer.writeStartElement("dataSet");

///////////////////////////////////

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

{

String elementName = "timesheet";

writer.writeStartElement(elementName);

System.out.println(i);

writeSimpleElement("kx"+i, i+"", writer);

writeSimpleElement("kkx"+i, i+"", writer);

writer.writeEndElement();

}

writer.writeEndElement();

writer.writeEndDocument();

writer.flush();

writer.close();

outputStreamZip.flush();

outputStreamZip.close();

outputStreamZip = null;

writer = null;

byte [] res  = o.toByteArray();

o.flush();

o.close();

res=null;

factory=null;

Scanner scanner = new Scanner(System.in);

String username = scanner.next();

Comments

Post Details

Added on Apr 18 2019
0 comments
146 views