[ 
http://issues.apache.org/jira/browse/XERCESC-1589?page=comments#action_12414565 
] 

Rinil Baxi commented on XERCESC-1589:
-------------------------------------

Alberto,

Thanks for the analysis and reply.
Even I have gone through the code and check this scenario completely.
I have designed one simple test case with malloc and free; and also with new 
and delete.
It shows that when I call free/delete, my object releases memory; but my 
process still owning this free chunk and this chunk is available for next 
allocation within that application. 
So I conclude that this is not the problem of memory leak or memory usage but 
the problem with free and delete design. It has nothing to do with XML Parser.

Here I am attaching the sample test program and also its output.

------ Memtest.hpp ------------------

#include <iostream>
#include <string>

class memTest
{
  private:
        int* i;
        char* ch;

  public:
        memTest();
        ~memTest();
        void MyPrint();
};

// Constructor
memTest::memTest()
{
        i = new int[100000];
        ch = (char*)malloc(100000);
}

// Destructor
memTest::~memTest()
{
        delete[] i;
        free(ch);
}

// Print Function - Dummy method of the class
void memTest::MyPrint()
{
        for (int j=0;j<100000;j++)
             i[j]=j;
        for (int j=0;j<100000;j++)
             ch[j]='A';
}
------------ test.cpp ------------------------
#include <cextdecs.h (PROCESS_GETINFOLIST_, PROCESSHANDLE_GETMINE_)>
#include "memTest.hpp" // Test class
#include <stdlib.h>
using namespace std;

// Shows current heap usage of the process
unsigned long getMemUsage ()
{
        short gError = 0;
        short myHandle[10];
        short attrList[10];
        short valList[10];
        short valMaxLen = 10;
        short valLen = 0;
        short attrs = 0;
        unsigned long *memUsage;

        gError = PROCESSHANDLE_GETMINE_ (&myHandle[0]);

        if (gError)
             return 0;

        memset (&attrList[0], '\0', 10);
        memset (&valList[0], '\0', 10);
        attrList[attrs] = 111;
        attrs++;

        gError = PROCESS_GETINFOLIST_
             (,,,,&myHandle[0]
              ,&attrList[0]
              ,attrs
              ,&valList[0]
              ,valMaxLen
              ,&valLen
             );

        if (gError)
             return 0;

        memUsage = (unsigned long *) (&valList[0]);
        return *memUsage;
}

int main()
{
        int iterations=5;

        std::cout << "\nMEMUSAGE at Start : "<< getMemUsage();

        for (int i = 1; i < iterations; i++)
        {
             memTest* newObject = new memTest();
             std::cout<< "\n\nIteration NO : " <<i;
             std::cout<< "\n--------- --  ";
             std::cout<< "\nMEMUSAGE after creation of object: "<< 
getMemUsage();
             newObject->MyPrint();
             delete newObject;
             std::cout<< "\nMEMUSAGE after deletion of object: "<< 
getMemUsage();
        }
        std::cout<<"\n";
        return 0;
}

------------------ output ---------------------------------

MEMUSAGE at Start : 24576

Iteration NO : 1
--------- --
MEMUSAGE after creation of object: 524592
MEMUSAGE after deletion of object: 524592

Iteration NO : 2
--------- --
MEMUSAGE after creation of object: 524592
MEMUSAGE after deletion of object: 524592

Iteration NO : 3
--------- --
MEMUSAGE after creation of object: 524592
MEMUSAGE after deletion of object: 524592

Iteration NO : 4
--------- --
MEMUSAGE after creation of object: 524592
MEMUSAGE after deletion of object: 524592

-------------------------------------------------------------------------------------

I got this results on HP Tandem NSK.
I dont know the behaviour of free and delete on other operating systems.

I dont have systems with solaris or linux platforms.
Could  you please confirm, if feasible, whether similar behaviour is observerd 
on Solaris and Linux platform also.

Thanks in advance.

Best Regards,
Rinil

> XML DOM parser does not release memory on parser:release and 
> resetDocumentPool()
> --------------------------------------------------------------------------------
>
>          Key: XERCESC-1589
>          URL: http://issues.apache.org/jira/browse/XERCESC-1589
>      Project: Xerces-C++
>         Type: Bug

>   Components: DOM
>     Versions: 2.4.0
>  Environment: HP-Tandem-NonStop Kernel
>     Reporter: Rinil Baxi

>
> 1) Use the following code:
> /home/Rinil/Xml/dom [2441]: more mleak.cpp
> #include < string.h>
> #include < cextdecs.h>
> #include < iostream>
> #include < xercesc/util/PlatformUtils.hpp>
> #include < xercesc/parsers/AbstractDOMParser.hpp>
> #include < xercesc/dom/DOMImplementation.hpp>
> #include < xercesc/dom/DOMImplementationLS.hpp>
> #include < xercesc/dom/DOMImplementationRegistry.hpp>
> #include < xercesc/dom/DOMBuilder.hpp>
> #include < xercesc/dom/DOMException.hpp>
> #include < xercesc/dom/DOMDocument.hpp>
> #include < xercesc/dom/DOMNodeList.hpp>
> #include < xercesc/dom/DOMError.hpp>
> #include < xercesc/dom/DOMLocator.hpp>
> #include < xercesc/dom/DOMWriter.hpp>
> #include < xercesc/framework/StdOutFormatTarget.hpp>
> #include < xercesc/framework/LocalFileFormatTarget.hpp>
> #include < xercesc/framework/MemBufInputSource.hpp>
> #include < xercesc/framework/Wrapper4InputSource.hpp>
> #include < xercesc/parsers/XercesDOMParser.hpp>
> #include < xercesc/util/XMLUni.hpp>
> #include < xercesc/util/XMLException.hpp>
> unsigned long getMemUsage ()
> {
>  short gError = 0;
>  short myHandle[10];
>  short attrList[10];
>  short valList[10];
>  short valMaxLen = 10;
>  short valLen = 0;
>  short attrs = 0;
>  unsigned long *memUsage;
>  gError = PROCESSHANDLE_GETMINE_ (&myHandle[0]);
>  if (gError)
>   return 0;35%)
>  memset (&attrList[0], '\0', 10);
>  memset (&valList[0], '\0', 10);
>  attrList[attrs] = 111;
>  attrs++;
>  gError = PROCESS_GETINFOLIST_
>   (,,,,&myHandle[0]
>   ,&attrList[0]
>   ,attrs
>   ,&valList[0]
>   ,valMaxLen
>   ,&valLen
>   );
>  if (gError)
>   return 0;
>  memUsage = (unsigned long *) (&valList[0]);
>  return *memUsage;
> }
> int main()
> {
>  DOMImplementation *impl;
>  DOMBuilder *parser;
>  DOMDocument *doc;
>  const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
>  std::cout < < "\nMEMUSAGE at Start : "< < getMemUsage();
>  // Initialize the XML system
>  try {
>         XMLPlatformUtils::Initialize();
>         XMLPlatformUtils::recognizeNEL(false);
>   }
>  catch (const XMLException& toCatch) {
>           return 1;
>  }
>  impl = DOMImplementationRegistry::getDOMImplementation(gLS);
>  parser = 
> ((DOMImplementationLS*)impl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS,
>  0);
>  if (parser == NULL) {
>   //Its known that XML system must be terminated before returning
>   return 1;
>  }
>  parser->setFeature(XMLUni::fgDOMNamespaces,true);
>  parser->setFeature(XMLUni::fgXercesSchema, false);
>  parser->setFeature(XMLUni::fgXercesSchemaFullChecking, false);
>  parser->setFeature(XMLUni::fgDOMValidateIfSchema, false);
>  parser->setFeature(XMLUni::fgDOMDatatypeNormalization, true);
>  //Reset Document Pool
>  parser->resetDocumentPool();
>  std::cout< < "\nMEMUSAGE before parsing: "< < getMemUsage();
>  //Parse XML and get document
>  try{
>   doc = parser->parseURI("personal.xml");
>  }
>  catch(DOMException dome){
>   //Its known that XML system must be terminated before returning
>   return 1;
>  }
>  std::cout< < "\nMEMUSAGE after parsing: "< < getMemUsage();
>  //Reset Document Pool
>  parser->resetDocumentPool();
>  std::cout< < "\nMEMUSAGE after resetDocumentpool(): "< < getMemUsage();
>  //Release Parser
>  //This should also release DOMDOcument associated i.e. doc
>  parser->release();
>  std::cout< < "\nMEMUSAGE after parser release(): "< < getMemUsage();
>  XMLPlatformUtils::Terminate();
>  std::cout< < "\nMEMUSAGE after Terminate(): "< < getMemUsage()< < std::endl;
>  return 0;
> }
> /home/Rinil/xml/dom [2442]:
> 2) Compile using Makefiles provided with XML samples.
> 3) Place a xml file to be parsed in the CWD. ie personal.xml which comes with
> the samples.
> 4) run mleak:
> /home/RinilXml/dom [2452]: ./mleak
> MEMUSAGE at Start : 16384
> MEMUSAGE before parsing: 57344
> MEMUSAGE after parsing: 245888
> MEMUSAGE after resetDocumentpool(): 245888
> MEMUSAGE after parser release(): 245888
> MEMUSAGE after Terminate(): 245888

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.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