Click here to Skip to main content
15,900,110 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralUsing Property Pages to Display ODBC Database Pin
dsouthard11-Mar-02 12:39
dsouthard11-Mar-02 12:39 
GeneralCHtmlView question Pin
Chris Losinger11-Mar-02 12:22
professionalChris Losinger11-Mar-02 12:22 
GeneralAfxGetMainWnd() from a Worker Thread Pin
Giles11-Mar-02 11:03
Giles11-Mar-02 11:03 
GeneralRe: AfxGetMainWnd() from a Worker Thread Pin
Morozov Alexey11-Mar-02 12:20
Morozov Alexey11-Mar-02 12:20 
GeneralRe: AfxGetMainWnd() from a Worker Thread Pin
Giles12-Mar-02 12:29
Giles12-Mar-02 12:29 
GeneralRe: AfxGetMainWnd() from a Worker Thread Pin
Nish Nishant11-Mar-02 14:04
sitebuilderNish Nishant11-Mar-02 14:04 
GeneralRe: AfxGetMainWnd() from a Worker Thread Pin
Giles12-Mar-02 12:26
Giles12-Mar-02 12:26 
GeneralCObArray - Destructors for CObject Pin
dazinith11-Mar-02 10:36
dazinith11-Mar-02 10:36 
Hio again.. I have a class (CCompanyHandler) which loads and saves a CObArray which is full of CObjects. The load file function calls the CObject constructors, and I'm trying to figure out how to destruct all of these objects created when loaded. I figure if I can overload the CCompanyHandler destructor then I should be able to have it destruct all of the CObjects, but I still have some sort of memory leak. Here is a trace:

CCompanyHandler:Constructor
CCompanyHandler:LoadFile
CCompany:Contructor <+ 1

CCompanyHandler:Constructor
CCompanyHandler:LoadFile
CCompany:Contructor <+ 2

CCompanyHandler:Constructor
CCompanyHandler:LoadFile
CCompany:Contructor <+ 3
CCompanyHandler:LoadFile
CCompany:Contructor <+ 4

CCompanyHandler:Destructor
CCompany:Destructor <- 3
CCompanyHandler:Destructor
CCompany:Destructor <- 2
CCompanyHandler:Destructor
CCompany:Destructor <- 1

As you can see the LoadFile() function of CCompanyHandler is what calls the constructors for the objects as it reads them.

TRACE("CCompanyHandler:LoadFile\n");
try
{
CFile fileMyFile(m_strFileName,CFile::modeRead + CFile::modeNoTruncate); //open file for reading
CArchive arRead(&fileMyFile, CArchive::load); //open archive for loading
m_oaCompanies.Serialize(arRead); //call serialize function to populate m_oaCompanies
arRead.Close(); // close archive
fileMyFile.Close(); // close file
return 1;
}

My problem is that if I call the loadfile() function multiple times it will keep creating instances of CCompany, and then my destructor doesn't get rid of it.. here is what my destructor does:

TRACE("CCompanyHandler:Destructor\n");
if (GetSize() > 0)
for (int i = 0; i < GetSize(); i++)
((CCompany*)m_oaCompanies[i])->~CCompany();

As you can see this only calls the destructor for each of the objects in the CObArray, not all of the objects which were actually made by the loadfile() function..

basicly i am clueless on proper destruction right now, and I'm getting tons of memory leaks when I debug, any suggestions on proper destruction of pointers and such will be MOST appreciated.

-dz
GeneralODBC and ExecuteSQL Pin
Yousuf11-Mar-02 10:04
Yousuf11-Mar-02 10:04 
GeneralRe: ODBC and ExecuteSQL Pin
Carlos Antollini11-Mar-02 10:46
Carlos Antollini11-Mar-02 10:46 
GeneralRe: ODBC and ExecuteSQL Pin
Yousuf12-Mar-02 9:21
Yousuf12-Mar-02 9:21 
GeneralWhich software updates NT to MSVCRT.DLL (6.00.8797) Pin
Hoang Le11-Mar-02 9:05
Hoang Le11-Mar-02 9:05 
GeneralRe: Which software updates NT to MSVCRT.DLL (6.00.8797) Pin
Derek Waters11-Mar-02 11:28
Derek Waters11-Mar-02 11:28 
GeneralTransparency and IPicture Pin
Derek Lakin11-Mar-02 8:46
Derek Lakin11-Mar-02 8:46 
GeneralSIMPLE QUESTION Pin
11-Mar-02 8:20
suss11-Mar-02 8:20 
GeneralRe: SIMPLE QUESTION Pin
Christian Graus11-Mar-02 8:23
protectorChristian Graus11-Mar-02 8:23 
GeneralRe: SIMPLE QUESTION Pin
Mazdak11-Mar-02 9:14
Mazdak11-Mar-02 9:14 
GeneralEdit Boxes\ Rich Edit Pin
11-Mar-02 8:18
suss11-Mar-02 8:18 
GeneralRe: Edit Boxes\ Rich Edit Pin
Christian Graus11-Mar-02 8:24
protectorChristian Graus11-Mar-02 8:24 
GeneralMetafiles (Scaling and Offseting) Pin
MikeG11-Mar-02 7:53
MikeG11-Mar-02 7:53 
GeneralRe: Metafiles (Scaling and Offseting) Pin
Paul M Watt11-Mar-02 8:44
mentorPaul M Watt11-Mar-02 8:44 
GeneralVC.NET and Winforms Pin
DaveJF11-Mar-02 7:26
DaveJF11-Mar-02 7:26 
GeneralAccessing the manufacturer name of a hard drive Pin
Zindine11-Mar-02 7:20
Zindine11-Mar-02 7:20 
GeneralRe: Accessing the manufacturer name of a hard drive Pin
Tim Smith11-Mar-02 7:29
Tim Smith11-Mar-02 7:29 
Generalaccessing members variables/function from within a thread Pin
Merle Pittman11-Mar-02 7:02
Merle Pittman11-Mar-02 7:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.