?
Solved

Detected memory leaks!

Posted on 1997-12-05
4
Medium Priority
?
336 Views
Last Modified: 2013-11-20
I have written a program with VC++ v5.0

I have no problem on compile it and run it, but after I quit the program(normally), I found that something appear in the debug window.

It stated the following.....
Detected memory leaks!
Dumping objects ->
C:\myprogram(188) : {263} normal block at 0x007F4970, 16 bytes long.
...........

But in myprogram line no. 188, the statement is just "CRect *rect = new CRect;"

What's the problem in this line??
0
Comment
Question by:Hardaway
[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
4 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1311739
Are you deleting the memory? It appears that you have not deleted the memory, which is why the runtime libraries are complaining.
0
 
LVL 3

Accepted Solution

by:
shaig earned 40 total points
ID: 1311740
In the debug version of MFC dll's there is a mechanism that keeps track after dynamic allocation and deallocation, if you get this message then it means that the memory that you allocated in this line, was not deleted.  check all execution paths and see that you did delete the CRect memory in all ways.
thui's answer is corrent, thats why he should get the points, if you like my explanation better then give them to me  :-)

p.s.    if you are still convinced that the memory is deleted, we can discuss that, there are a some very interesting ways for debugging things like that.


0
 
LVL 1

Author Comment

by:Hardaway
ID: 1311741
I made a mistake in deallocating the memory, so that why I have
an error when I run the program.

But now I have another problem, just take a look on the source code first:

Object::myfunc()
{
    for (int i = 0; i < limit; i ++)
        BOject[i] = new CObject;
}

BObject is declare as ClassName *BObject[limit]
and I have delete [] *BObject

However,still "Detected memory leaks"


0
 
LVL 3

Expert Comment

by:shaig
ID: 1311742
Yuo have deleted the array of pointers, but not the data that the pointers have pointed to.
you should add ( bofeor doing what you are right now ) a 'for'
that will delete the data itself - very simular to the allocations.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

752 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