Re: Why a Memory Leak Here:
On 2011-01-19 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 },
{ L".html", L"_ekko.html", EKKO_HTML },
{ L".asp", L"_ekko.asp", EKKO_ASP },
{ L".ekko", L"", EKKO_EKKO },
{ L"_ekko.htm", L".htm", EKKO_EKKO_EXT },
{ L"_ekko.html", L".html", EKKO_EKKO_EXT },
{ L"_ekko.asp", L".asp", EKKO_EKKO_EXT },
{ L".aspx", L".aspx_ekko.exclude", EKKO_ASPX },
{ L"*_ekko.exclude", L"", EKKO_EXCLUDE },
{ L".vb", L".vb_ekko.exclude", EKKO_VB },
{ L".cs", L".cs_ekko.exclude", EKKO_CS },
{ L".css", L".css_ekko.exclude", EKKO_CSS },
{ L".config", L".config_ekko.exclude", EKKO_CONFIG },
{ L".resx", L".resx_ekko.exclude", EKKO_RESX },
{ L".master", L".master_ekko.exclude", EKKO_MASTER },
{ L".dll", L".dll_ekko.exclude", EKKO_DLL },
{ L".ascx", L".ascx_ekko.exclude", EKKO_ASCX }, //added by saleh
};
From what you are presenting to us, there is nothing wrong and nothing
to be changed. Two things are coming into my mind:
1) EkkoBackupFileType is a class type that is defined in a fragile way
and does not properly cleanup it's allocated resources in the destructor.
2) EKKO_FILETYPES is an array of static storage duration. It's either
local or non-local, but in either case it will be destroyed very late
during runtime and the diagnostic tool you are using does diagnose this
situation incorrectly because it is no longer observing the storage at
this very late point in time.
HTH & Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]