473,324 Members | 2,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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

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

May 3 '07 #1
2 3859
Is the CMap it self being deleted? can you post some codes?

WJ

"Sean F. Aitken" wrote:
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

May 4 '07 #2
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

WJ wrote:
Is the CMap it self being deleted? can you post some codes?

WJ

"Sean F. Aitken" wrote:
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
May 8 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rob Richardson | last post by:
Greetings! I am running into a problem with implicit conversion of arguments when trying to insert the contents of a CString object into a stringstream. I am using the following typedef: ...
0
by: Chris | last post by:
Hi all, Just converted our 95 project workspace file from VC++ 6.0 to .NET, and things have gone...um...pretty well. Down to the last of the suffering - our main server application is doing...
5
by: raz | last post by:
Greetings all. I apologize for what is almost certainly a stupid question, but I can't figure this out, and have no more time for head bashing... The short version: what is the appropriate...
4
by: Stephen Engle | last post by:
I am attempting to write a C# program that accesses a C++ library. The library has functions that return CStrings. So far I have not been able to find a way to declare the function prototype in...
1
by: Klynt | last post by:
Project built using /CLR, but code is old and has not been converted specifically to "managed" (__gc or __value). Everything seemed to work great, until I got the following error. I have a...
8
by: Tony H | last post by:
Is there a way to read an MFC serialized class containing CStrings, ints, and doubles using a CLR-based class? Specifically, to get CString into System::String? Bye the Bye, is System:: String...
0
by: Sebastian Dau | last post by:
Hello Newsgroup, I'm struggeling with wrapping a dll using MFC CStrings. Code: class CLASSEXPORTDLL_API CClassExportDll { public:
4
by: Cactus | last post by:
How to convert unsigned char* to CString: I wrote some function: u_char_ =55; u_char_ =66; u_char_ =77; .........=ii...... Convert_to_CS(u_char_);
3
by: Rob Prins | last post by:
{ This is probably a non-environment-specific problem buried in an environment-specific context; thus accepted. -mod } L.S. For a couple of days I've been trying to write a small Windows...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.