Return-Path: Delivered-To: apmail-ws-axis-c-dev-archive@www.apache.org Received: (qmail 33570 invoked from network); 19 Apr 2004 00:09:34 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 19 Apr 2004 00:09:34 -0000 Received: (qmail 33373 invoked by uid 500); 19 Apr 2004 00:09:18 -0000 Delivered-To: apmail-ws-axis-c-dev-archive@ws.apache.org Received: (qmail 33364 invoked by uid 500); 19 Apr 2004 00:09:18 -0000 Mailing-List: contact axis-c-dev-help@ws.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: List-Id: "Apache AXIS C Developers List" Reply-To: "Apache AXIS C Developers List" Delivered-To: mailing list axis-c-dev@ws.apache.org Received: (qmail 33346 invoked from network); 19 Apr 2004 00:09:18 -0000 Received: from unknown (HELO EXCHANGEUS.edocs.com) (63.114.227.95) by daedalus.apache.org with SMTP; 19 Apr 2004 00:09:18 -0000 Received: by exchangeus.edocs.com with Internet Mail Service (5.5.2650.21) id ; Sun, 18 Apr 2004 20:08:47 -0400 Message-ID: <8A6229AB5BE35447A7A838D64C1792BB12C1B4BE@exchangeus.edocs.com> From: Lilantha Darshana To: 'Apache AXIS C Developers List' Subject: RE: Use of STL map (and memory leaks) - patch Date: Sun, 18 Apr 2004 20:08:43 -0400 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: text/plain; charset="iso-8859-1" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N The rule of thumb is if you use STL map and using dynamically allocated objects in the value (in a key-value pair), it is your responsibility to deallocate all the values from the map. The std::map does not call the destructors of pointer variables stored in the std::pairs of std::map. Our impl. of a map is not a good approach because, you can't defeat the power & performance of the STL impl. Try to avoid STL as possible as you can, and go for a simple solution, and go for STL where you can't avoid it -- for example if you want to store and retrieve more than one key-value pairs and does not know exactly how many objects to store then you have to think about using std::map, because it has everything you want. And need to think about portability as well. Correct way to handle this is to pass in a allocator, you can create your own custom allocators and impl. void allocator::destroy(pointer p) and void allocator::deallocate(pointer ptr, sise_type num) method correctly. regards -Lilantha -----Original Message----- From: Samisa Abeysinghe [mailto:samisa_abeysinghe@yahoo.com] Sent: Wednesday, April 14, 2004 1:45 AM To: axis-c-dev@ws.apache.org Subject: Use of STL map (and memory leaks) - patch Hi All, The use of STL map seems to cause memeory leaks (it leaves 'reachable memory' behind after client terminates) It is quite possible to do without the STL map in some cases. I have done this for SoapKeywordMapping. (see patch below) In cases it is difficult to replace maps with arrays (as an exampel when key is a string) we may have to look for alternatives. Is it possible to replace STL map with our own map? (I think to do this without templates, we have to stick to string keys) I also fixed some memory leaks in SoapKeywordMapping code. Need to call SoapKeywordMapping::uninitialize () from Axis.cpp uninitialize_module() to make this effextive. Please update the CVS with the patch. (SoapKeywordMapping.h, SoapKeywordMapping.cpp and Axis.cpp) Thanks, Samisa... Here is the patch... --------------------------------------------- diff -u ../../original/ws-axis/c/src/soap/SoapKeywordMapping.h ./src/soap/SoapKeywordMapping.h --- ../../original/ws-axis/c/src/soap/SoapKeywordMapping.h 2004-04-08 16:42:47.000000000 +0600 +++ ./src/soap/SoapKeywordMapping.h 2004-04-13 15:57:01.000000000 +0600 @@ -17,6 +17,7 @@ #if !defined(AXIS_SOAPKEYWORDMAPPING_H__INCLUDED_) #define AXIS_SOAPKEYWORDMAPPING_H__INCLUDED_ +#include "../common/AxisUtils.h" #include #include @@ -43,11 +44,13 @@ SoapKeywordMapping(); virtual ~SoapKeywordMapping(); private: - static map m_Map; + //static map m_Map; + static SoapKeywordStruct m_Map[VERSION_LAST]; static volatile bool m_bInit; public: static void Initialize(); - static const SoapKeywordStruct& Map(int nVersion); + static void uninitialize(); + static const SoapKeywordStruct& Map(int nVersion); }; #endif -------------------------------------------- diff -u ../../original/ws-axis/c/src/soap/SoapKeywordMapping.cpp ./src/soap/SoapKeywordMapping.cpp --- ../../original/ws-axis/c/src/soap/SoapKeywordMapping.cpp 2004-04-08 15:40:27.000000000 +0600 +++ ./src/soap/SoapKeywordMapping.cpp 2004-04-13 15:59:01.000000000 +0600 @@ -21,9 +21,10 @@ #include "SoapKeywordMapping.h" #include -#include "../common/AxisUtils.h" +//#include "../common/AxisUtils.h" -map SoapKeywordMapping::m_Map; +//map SoapKeywordMapping::m_Map; +SoapKeywordStruct SoapKeywordMapping::m_Map[VERSION_LAST]; volatile bool SoapKeywordMapping::m_bInit = false; #define __TRC(X) AxisUtils::ToAxisXMLCh(X) @@ -35,7 +36,7 @@ SoapKeywordMapping::~SoapKeywordMapping() { - +// m_Map.clear(); } void SoapKeywordMapping::Initialize() @@ -44,9 +45,9 @@ { for (int sv = SOAP_VER_1_1; sv < VERSION_LAST; sv++) { - m_Map[sv].pchNamespaceUri = + m_Map[sv].pchNamespaceUri = __TRC(gs_SoapEnvVersionsStruct[sv].pchNamespaceUri); - m_Map[sv].pchPrefix = + m_Map[sv].pchPrefix = __TRC(gs_SoapEnvVersionsStruct[sv].pchPrefix); for (int sw = SKW_ENVELOPE; sw < SOAP_WORDS_LAST; sw++) { @@ -72,6 +73,21 @@ } } +void SoapKeywordMapping::uninitialize() +{ + if (m_bInit) + { + /* soap 1.1 envelop attributes */ + delete m_Map[SOAP_VER_1_1].pEnv; + delete m_Map[SOAP_VER_1_1].pXsi; + delete m_Map[SOAP_VER_1_1].pXsd; + delete m_Map[SOAP_VER_1_2].pEnv; + delete m_Map[SOAP_VER_1_2].pXsi; + delete m_Map[SOAP_VER_1_2].pXsd; + m_bInit = false; + } +} + const SoapKeywordStruct& SoapKeywordMapping::Map(int nVersion) { return m_Map[nVersion]; -------------------------------------------------------- diff -u ../../original/ws-axis/c/src/engine/Axis.cpp src/engine/Axis.cpp --- ../../original/ws-axis/c/src/engine/Axis.cpp 2004-04-08 18:07:54.000000000 +0600 +++ src/engine/Axis.cpp 2004-04-13 11:22:27.000000000 +0600 @@ -316,8 +316,11 @@ extern "C" int uninitialize_module () { - // XMLPlatformUtils::Terminate(); +#ifdef USE_XERCES_PARSER + XMLPlatformUtils::Terminate (); +#endif ModuleUnInitialize (); + SoapKeywordMapping::uninitialize (); return AXIS_SUCCESS; } __________________________________ Do you Yahoo!? Yahoo! Tax Center - File online by April 15th http://taxes.yahoo.com/filing.html