Skip to main content

Memory usage of DocumentBuilderFactory

No replies
Joined: 2006-04-24

I need to create a method that will probably will be called 50 million times. In this method I will parse the xml document. My question is that should I keep the following as a member variable or method local variable:

DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
builder = dbFactory.newDocumentBuilder();

void x (){
Document document = builder.parse(new ByteArrayInputStream(reply));

I am not sure of memory usage and also which one is more efficient. I am also not sure if builder.parse keeps the reference to memory around. If that's the case then all that should be local to the method. Any suggestion about how this should be done?