Solved

Initializing a CMemFile derived class

Posted on 1998-11-05
2
376 Views
Last Modified: 2013-11-20
To work on a file i have derived one class from CMemFile.
Then the idea is to load the memory with the file (its working fine)
the problem is that everytime i end the application this appears in the output window:
"
Detected memory leaks!
Dumping objects ->
{56} normal block at 0x00674260, 1000 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.
"

here how i am creating my class CIntelHexaFile

BYTE *pBuf = (BYTE*) new BYTE(10000);
m_HexaMem  = (CIntelHexaFile*) new CIntelHexaFile(pBuf,10000,5000);

this is done in other object constructor. In the destructor i do :
delete m_HexaMem;

m_HexaMem is declared as CIntelHexaFile * m_HexaMem.


Can anyone tell me what is the problem?
(pBuf is destructed be the CMemFile destructor.Right?)
0
Comment
Question by:jmartins71
2 Comments
 
LVL 2

Accepted Solution

by:
jstolan earned 50 total points
ID: 1324254
pBuf will only be destroyed if the CMemFile m_bAutoDelete member variable is TRUE.  When you create the class with the constructor you have chosen, m_bAutodelete initializes to FALSE.

Since you are creating the buffer, it's probably cleaner for you to delete it explicitly.  For the record, here is the destructor of CMemFile:

CMemFile::~CMemFile()
{
      // Close should have already been called, but we check anyway
      if (m_lpBuffer)
            Close();
      ASSERT(m_lpBuffer == NULL);

      m_nGrowBytes = 0;
      m_nPosition = 0;
      m_nBufferSize = 0;
      m_nFileSize = 0;
}

And here is the close function it calls:

void CMemFile::Close()
{
      ASSERT_VALID(this);

      m_nGrowBytes = 0;
      m_nPosition = 0;
      m_nBufferSize = 0;
      m_nFileSize = 0;
      if (m_lpBuffer && m_bAutoDelete)
            Free(m_lpBuffer);
      m_lpBuffer = NULL;
}


0
 

Author Comment

by:jmartins71
ID: 1324255
thanks jstolan.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
fizzArray2 challenge 1 60
changeXy challenge 13 57
Unix Command -- Challenging  question 7 79
Annoying "thing" blocks my view 4 51
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now