[ 
https://issues.apache.org/jira/browse/XERCESJ-1573?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13415778#comment-13415778
 ] 

Michael Glavassevich edited comment on XERCESJ-1573 at 7/16/12 11:29 PM:
-------------------------------------------------------------------------

I don't believe it either, but can explain why Mukul didn't see the problem.

A new Validator is being created on each loop in XS11Validate.java:

for (int indx = 0; indx < repeat; indx++) {
   Validator validator = schema.newValidator();
   validator.setErrorHandler(this);
   validator.validate(new StreamSource(xmlDoc));
}

Validators are reusable objects. For good performance it is best practice to 
reuse them and expect users of Xerces to be doing that.

Move the creation of the Validator outside of the loop you'll see the leak.

Validator validator = schema.newValidator();
validator.setErrorHandler(this);
for (int indx = 0; indx < repeat; indx++) {
    validator.validate(new StreamSource(xmlDoc));
}

XMLAssertPsychopathXPath2Impl keeps appending elements to the same Document.

It would look like this if you serialized it, where the number of 'test' 
elements == number of iterations. So yes, this is definitely leaking and not 
being reinitialized properly.

<test xmlns="http://www.rackspace.com/test/simple";
      start="2012-03-12T11:51:11Z" end="2012-03-13T11:51:11Z">
<test xmlns="http://www.rackspace.com/test/simple";
      start="2012-03-12T11:51:11Z" end="2012-03-13T11:51:11Z"/>
<test xmlns="http://www.rackspace.com/test/simple";
      start="2012-03-12T11:51:11Z" end="2012-03-13T11:51:11Z"/>
<test xmlns="http://www.rackspace.com/test/simple";
      start="2012-03-12T11:51:11Z" end="2012-03-13T11:51:11Z"/>
...
</test>
        
                
      was (Author: [email protected]):
    I don't believe it either, but can explain why Mukul didn't see the problem.

A new Validator is being created on each loop in XS11Validate.java:

for (int indx = 0; indx < repeat; indx++) {
   Validator validator = schema.newValidator();
   validator.setErrorHandler(this);
   validator.validate(new StreamSource(xmlDoc));
}

Validators are reusable objects. For good performance it is best practice to 
reuse them and expect users of Xerces to be doing that.

Move the creation of the Validator outside of the loop you'll see the leak.

Validator validator = schema.newValidator();
validator.setErrorHandler(this);
for (int indx = 0; indx < repeat; indx++) {
    validator.validate(new StreamSource(xmlDoc));
}

XMLAssertPsychopathXPath2Impl keeps appending elements to the same Document.

It would like this if you serialized it, where the number of 'test' elements == 
number of iterations. So yes, this is definitely leaking and not being 
reinitialized properly.

<test xmlns="http://www.rackspace.com/test/simple";
      start="2012-03-12T11:51:11Z" end="2012-03-13T11:51:11Z">
<test xmlns="http://www.rackspace.com/test/simple";
      start="2012-03-12T11:51:11Z" end="2012-03-13T11:51:11Z"/>
<test xmlns="http://www.rackspace.com/test/simple";
      start="2012-03-12T11:51:11Z" end="2012-03-13T11:51:11Z"/>
<test xmlns="http://www.rackspace.com/test/simple";
      start="2012-03-12T11:51:11Z" end="2012-03-13T11:51:11Z"/>
...
</test>
        
                  
> Possible memory leak when using assertions
> ------------------------------------------
>
>                 Key: XERCESJ-1573
>                 URL: https://issues.apache.org/jira/browse/XERCESJ-1573
>             Project: Xerces2-J
>          Issue Type: Bug
>          Components: XML Schema 1.1 Datatypes
>    Affects Versions: 2.11.0
>            Reporter: Jorge L. Williams
>            Priority: Blocker
>         Attachments: XS11Validate.java, d1.png, d2.png, d3.png, d4.png, 
> d5.png, d6.png, duration-sans-assert.xsd, duration.xsd, good.xml, mem.png
>
>


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to