Memory leak std::wstring L" "

S

schliz

I have a global variable in a cpp file, in this file there is the
implementation of a class. At the constructor, I set the example
variable to " ".

global variable in the same file:

####### file.cpp

std::wstring szVar;

in a constructor of a class in this file, I set this variable to " ":

CMyClass::CMyClass()
{
szVar = L" ";
}

###### file.cpp end


I get:
Detected memory leaks!
Dumping objects ->
{762} normal block at 0x039FAFE8, 16 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
CD

Thank you very much for your help.
Georg
 
I

Ismo Salonen

schliz said:
I have a global variable in a cpp file, in this file there is the
implementation of a class. At the constructor, I set the example
variable to " ".

global variable in the same file:

####### file.cpp

std::wstring szVar;

in a constructor of a class in this file, I set this variable to " ":

CMyClass::CMyClass()
{
szVar = L" ";
}

###### file.cpp end


I get:
Detected memory leaks!
Dumping objects ->
{762} normal block at 0x039FAFE8, 16 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
CD

Thank you very much for your help.
Georg

The dump is clearly part of MFC which is OT here.
Never trust MFC when it tells memory leaks, it detects them too early.
In this case there is no leak as the static is not cleared before MFC
detection.
ismo
 
J

James Kanze

I have a global variable in a cpp file, in this file there is
the implementation of a class. At the constructor, I set the
example variable to " ".
global variable in the same file:
####### file.cpp
std::wstring szVar;
in a constructor of a class in this file, I set this variable
to " ":
CMyClass::CMyClass()
{
szVar = L" ";
}
###### file.cpp end

Are there any static instances of CMyClass anywhere. You may be
encountering an order of initialization problems. (Also, I'd
avoid starting a class name with a capital C, followed by a
capital. That convention is used by Microsoft, to indicate that
the class is part of MFC.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top