Solved

Detected memory leaks!

Posted on 1997-12-05
4
313 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
  • 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 20 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

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
xyBalance chalenge 58 88
Get filename and folder into excel 7 68
unable to delete all specified values regedit 38 273
How to convert MFC::CString to UTF8 wchar_t* 10 139
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. …
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.
A simple description of email encryption using a secure portal service. This is one of the choices offered by The Email Laundry for email encryption. The other choices are pdf encryption which creates an encrypted pdf of your email and any attachmen…

911 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

23 Experts available now in Live!

Get 1:1 Help Now