Re: Why a Memory Leak Here:
On Jan 19, 4:03 am, "Martin B." <0xCDCDC...@gmx.at> wrote:
On 19.01.2011 03:59, achalk wrote:
I am using VC++ 2008. I declare the following global data structure.
When I run my program in debug mode and specify a dump of memory leaks
at the end I get leaked memory for all the strings in the data
structure.
Can anyone explain why, and how should I declare this data in order to
have the memory correctly destroyed at program end? Thanks.
const EkkoBackupFileType EKKO_FILETYPES[] =
{
{ L".htm", L"_ekko.htm", EKKO_HTM },
(...)
*Dynamic* leak detection only picks up *dynamic* leaks.
In the case of Visual C++ CRT, the leak detection is built into the
malloc implementation. (There is also one for MFC, maybe you should
specify further how exactly you "specify a dump of memory leaks".)
Since your global array does not involve malloc, it is not this array
that is leaked, but something else! (A copy of the strings?)
See this MS article about _crtBreakAlloc for how to find the allocation
that is leaked:http://support.microsoft.com/?scid=kb%3Ben-us%3B151585&x=6&y=10
br,
Martin
Thanks for your replies.
1) EkkoBackupFileType is defined as:
struct EkkoBackupFileType
{
std::wstring ext;
std::wstring bkp;
int type;
}
2) _crtBreakAlloc was set with:
#if defined(_DEBUG)
int nOldState = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
nOldState |= _CRTDBG_LEAK_CHECK_DF;
nOldState |= _CRTDBG_CHECK_ALWAYS_DF;
_CrtSetDbgFlag(nOldState);
_CrtSetBreakAlloc(231);
#endif
where 231 was the first allocation number shown as 'leaked' in the
dump at the end of the program.
3) I posted here because I did not see why a global (non-dynamic)
memory allocation should show up as a leak. Martin B's suggestion
seems closest but I cannot find any copies of this array in the code.
4) So this is still a mystery;
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]