CMap<long,long,CString,LPCSTR> ... are the CStrings being deleted?

  • Thread starter Thread starter Sean F. Aitken
  • Start date Start date
S

Sean F. Aitken

Good afternoon,

We have an app that uses a CMap with CString types for values and
accepts LPCSTR as the parameter. The object being created is on the
heap (created dynamically). A leak detector we have is picking up the
CStrings as not being freed. Based on the CMap documentation, the
values are deleted when the CMap is destroyed. (In this case, the
value IS the CString itself, not a pointer to a CString) All the
examples I see indicate the use of pointers to CStrings, then in the
destructor (or calling routine), the CStrings referenced by the
pointers are individually deleted in a loop before the CMap is
destroyed.

Is there something fishy going on here that is causing the CString
values not to be deleted? Perhaps because we are using LPCSTR as
parameter values. Any help is greatly appreciated.

Thank you,
-Sean
 
Hi WJ,

It turns out that it was a false positive memory leak that I was
witnessing. The CString default assignment operator was where the
original memory allocation was taking place. Turns out that it was a
few layers up (above the CMap) where the, in this case, VariantClear
wasn't being called.

Forry for any confusion, but it does appear that when the CMap is
destroyed the CString values are also released.

Cheers!
-Sean
 
Back
Top