V
vidya.bhagwath
Hello Experts,
I am using std::string object as a member variable in one of the my
class. The same class member function operates on the std::string
object and it appends some string to that object. My sample code is as
follows.
["CTestMemoryLeak" is the class name and "GiveString" is the function
which appends string to the std::string object. Here "m_String" is the
std::string object.]
..h file content----------
#include <stdio.h>
#include <string>
class CTestMemoryLeak
{
public:
CTestMemoryLeak();
~CTestMemoryLeak();
std::string m_String;
void GetString();
void GiveString(std::string& m_String);
};
..cpp file content--------------------
void CTestMemoryLeak::GetString()
{
GiveString(m_String);
}
void CTestMemoryLeak::GiveString(std::string& m_String)
{
short snCount = 4;
do
{
m_String.append("TestMemoryLeak");
snCount--;
}while(snCount!=0);
}
I am testing this code using Rational TestRT and I am getting
"Potential Memory leak". But in the above example if i use the local
std::string object instead of the "m_String", which is the member
variable of my class "CTestMemoryLeak" I am not getting any Potential
memory leak. Can anybody tell me the reason for this?
I am using VC6.0 and Windows XP.
Thanks in advance for any help.
Thanks & Regards,
Vidya Bhagwath
I am using std::string object as a member variable in one of the my
class. The same class member function operates on the std::string
object and it appends some string to that object. My sample code is as
follows.
["CTestMemoryLeak" is the class name and "GiveString" is the function
which appends string to the std::string object. Here "m_String" is the
std::string object.]
..h file content----------
#include <stdio.h>
#include <string>
class CTestMemoryLeak
{
public:
CTestMemoryLeak();
~CTestMemoryLeak();
std::string m_String;
void GetString();
void GiveString(std::string& m_String);
};
..cpp file content--------------------
void CTestMemoryLeak::GetString()
{
GiveString(m_String);
}
void CTestMemoryLeak::GiveString(std::string& m_String)
{
short snCount = 4;
do
{
m_String.append("TestMemoryLeak");
snCount--;
}while(snCount!=0);
}
I am testing this code using Rational TestRT and I am getting
"Potential Memory leak". But in the above example if i use the local
std::string object instead of the "m_String", which is the member
variable of my class "CTestMemoryLeak" I am not getting any Potential
memory leak. Can anybody tell me the reason for this?
I am using VC6.0 and Windows XP.
Thanks in advance for any help.
Thanks & Regards,
Vidya Bhagwath