Kohinoor24
February 17th, 2003, 04:01 AM
I have located a memory leak in my program.It shoots up.I dont know why?.This is the implementation Iam doing & it is coming into picture only under Linux.
I have a class as follows:
class C_AfpDrawer:public I_Drawer
{
public: // c_Ptx is an object Iam creating
void StoreTablePtx(C_Ptx& Object);
C_Ptx * GetTablePtxObject();
//Destructor which Iam calling to delete the objects created.
C_AfpDrawer::~C_AfpDrawer()
{
delete m_Mdobject;
delete m_Idmobject;
delete m_Textptxobject;
delete m_Gobject;
delete m_Tableptxobject;
}
private:
C_Idm * m_Idmobject;
C_Ptx * m_Textptxobject;
//Iam showing only this pointer as an example.Iam doing the same with other pointers as well.
C_Ptx * m_Tableptxobject;
C_MixedData* m_Mdobject;
C_Goca *m_Gobject;
}
The implementation is as follows:
void C_AfpDrawer::StoreTablePtx(C_Ptx& Object)
{
m_Tableptxobject = &Object;
}
C_Ptx * C_AfpDrawer::GetTablePtxObject()
{
return m_Tableptxobject;
}
In another class say,C_Afppainter
C_Afppainter has a
C_AfpDrawer & m_drawer;//reference
void C_Afppainter::Func()
{
// This Func() function is called a lot of times & I need to create a new object each time it is called.
// So Iam doing as follows.
if (m_drawer.GetTablePtxObject())
delete (m_drawer.GetTablePtxObject());
C_Ptx *ptx = new C_Ptx();
m_drawer.StoreTablePtx(*ptx);
// So the last time Func() is called ,the object created Iam deleting in the C_AfpDrawer Destructor.
}
Is there a memory leak in what Iam doing....Please help..
I have a class as follows:
class C_AfpDrawer:public I_Drawer
{
public: // c_Ptx is an object Iam creating
void StoreTablePtx(C_Ptx& Object);
C_Ptx * GetTablePtxObject();
//Destructor which Iam calling to delete the objects created.
C_AfpDrawer::~C_AfpDrawer()
{
delete m_Mdobject;
delete m_Idmobject;
delete m_Textptxobject;
delete m_Gobject;
delete m_Tableptxobject;
}
private:
C_Idm * m_Idmobject;
C_Ptx * m_Textptxobject;
//Iam showing only this pointer as an example.Iam doing the same with other pointers as well.
C_Ptx * m_Tableptxobject;
C_MixedData* m_Mdobject;
C_Goca *m_Gobject;
}
The implementation is as follows:
void C_AfpDrawer::StoreTablePtx(C_Ptx& Object)
{
m_Tableptxobject = &Object;
}
C_Ptx * C_AfpDrawer::GetTablePtxObject()
{
return m_Tableptxobject;
}
In another class say,C_Afppainter
C_Afppainter has a
C_AfpDrawer & m_drawer;//reference
void C_Afppainter::Func()
{
// This Func() function is called a lot of times & I need to create a new object each time it is called.
// So Iam doing as follows.
if (m_drawer.GetTablePtxObject())
delete (m_drawer.GetTablePtxObject());
C_Ptx *ptx = new C_Ptx();
m_drawer.StoreTablePtx(*ptx);
// So the last time Func() is called ,the object created Iam deleting in the C_AfpDrawer Destructor.
}
Is there a memory leak in what Iam doing....Please help..