I am very new bee to C++ coding and STL library usage. I was quite interested on using STL library on my C++ program which I was developing. But recently I tried using Visual Leak detector and found many leaks which are specifically where ever I used STL library and new operator.
Since it is an runtime application I also found the CPU memory keeps increasing when I run the code for 4-5 days continuously. Learning on some of the forums and other noted, I understood that I need to delete/erase the content inside the std::map, std::unordered_map, std:set before calling its corresponding clear. My question here is if I do all those on the destructor calls which are never gonna called (since my programmer never going to STOP) will the STL library create memory leak every time I access it?
Is there an alternative for this?
Example: common.h
struct stTagElem_t {
uint32_t m_unOffset;
uint32_t m_unArraySize;
string m_acTagName;
string m_acTagValue;
string m_acDataType;
} ;
typedef std::unordered_map<uint8_t, stTagElem_t> tagsList_t;
struct stMappingElem_t {
uint16_t m_unMemSize;
tagsList_t m_stTagsList;
string m_acEventName;
string m_acMapTypeName;
} ;
typedef std::unordered_map<uint32_t, stMappingElem_t> eventDataMap_t;
dataMapManager.cpp //declared as global list since dataMapManager.cpp has all static functions
eventDataMap_t sm_eventDataMapList;
So When I use Visual Leak Detector It says the following:
---------- Block 596 at 0x00DE8DB8: 120 bytes ----------
Leak Hash: 0xB26C3A34, Count: 1, Total 120 bytes
Call Stack (TID 11580):
c:\program files (x86)\microsoft visual studio 14.0\vc\include\xmemory0 (977): example.exe!std::_Wrap_alloc<std::allocator<std::_List_node<std::pair<unsigned __int64 const ,stMappingElem_t>,void *> > >::allocate()
c:\program files (x86)\microsoft visual studio 14.0\vc\include\list (730): example.exe!std::_List_alloc<std::_List_base_types<std::pair<unsigned __int64 const ,stMappingElem_t>,std::allocator<std::pair<unsigned __int64 const ,stMappingElem_t> > > >::_Buynode0() + 0x11 bytes
c:\program files (x86)\microsoft visual studio 14.0\vc\include\list (716): example.exe!std::_List_alloc<std::_List_base_types<std::pair<unsigned __int64 const ,stMappingElem_t>,std::allocator<std::pair<unsigned __int64 const ,stMappingElem_t> > > >::_Buyheadnode()
c:\program files (x86)\microsoft visual studio 14.0\vc\include\list (649): example.exe!std::_List_alloc<std::_List_base_types<std::pair<unsigned __int64 const ,stMappingElem_t>,std::allocator<std::pair<unsigned __int64 const ,stMappingElem_t> > > >::_List_alloc<std::_List_base_types<std::pair<unsigned __int64 const ,stMappingElem_t>,std::al() + 0x8 bytes
c:\program files (x86)\microsoft visual studio 14.0\vc\include\list (826): example.exe!std::_List_buy<std::pair<unsigned __int64 const ,stMappingElem_t>,std::allocator<std::pair<unsigned __int64 const ,stMappingElem_t> > >::_List_buy<std::pair<unsigned __int64 const ,stMappingElem_t>,std::allocator<std::pair<unsigned __int64 const ,stMappin()
c:\program files (x86)\microsoft visual studio 14.0\vc\include\list (899): example.exe!std::list<std::pair<unsigned __int64 const ,stMappingElem_t>,std::allocator<std::pair<unsigned __int64 const ,stMappingElem_t> > >::list<std::pair<unsigned __int64 const ,stMappingElem_t>,std::allocator<std::pair<unsigned __int64 const ,stMappingElem_t> >()
c:\program files (x86)\microsoft visual studio 14.0\vc\include\xhash (197): example.exe!std::_Hash<std::_Umap_traits<unsigned __int64,stMappingElem_t,std::_Uhash_compare<unsigned __int64,std::hash<unsigned __int64>,std::equal_to<unsigned __int64> >,std::allocator<std::pair<unsigned __int64 const ,stMappingElem_t> >,0> >::_Hash<std::_Umap_tra() + 0xF bytes
c:\program files (x86)\microsoft visual studio 14.0\vc\include\unordered_map (119): example.exe!std::unordered_map<unsigned __int64,stMappingElem_t,std::hash<unsigned __int64>,std::equal_to<unsigned __int64>,std::allocator<std::pair<unsigned __int64 const ,stMappingElem_t> > >::unordered_map<unsigned __int64,stMappingElem_t,std::hash<unsigned __int6()
g:\mywork\src\datamapmanager.cpp (15): example.exe!`dynamic initializer for 'sm_eventDataMapList''() + 0xD bytes
d:\rs1\minkernel\crts\ucrt\src\appcrt\startup\initterm.cpp (22): ucrtbased.dll!_initterm()
f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (221): example.exe!__scrt_common_main_seh() + 0xF bytes
f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (296): example.exe!__scrt_common_main()
f:\dd\vctools\crt\vcstartup\src\startup\exe_main.cpp (17): example.exe!mainCRTStartup()
KERNEL32.DLL!BaseThreadInitThunk() + 0x24 bytes
ntdll.dll!__RtlUserThreadStart() + 0x2F bytes
ntdll.dll!_RtlUserThreadStart() + 0x1B bytes
Data:
38 09 E6 00 F0 98 E8 00 CD CD CD CD CD CD CD CD 8....... ........
CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD ........ ........
CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD ........ ........
CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD ........ ........
CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD ........ ........
CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD ........ ........
CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD ........ ........
CD CD CD CD CD CD CD CD ........ ........
Aucun commentaire:
Enregistrer un commentaire