Solved

Initializing a CMemFile derived class

Posted on 1998-11-05
2
379 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Expand macro to include alternate header placement and naming 5 66
sum28 challenge 31 106
zeroMAx challenge 20 88
Is there a simple front-end menu system. 9 71
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

895 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

14 Experts available now in Live!

Get 1:1 Help Now