Solved

Initializing a CMemFile derived class

Posted on 1998-11-05
2
395 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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…
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

623 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