Solved

Detected memory leaks!

Posted on 1997-12-05
4
301 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

707 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

17 Experts available now in Live!

Get 1:1 Help Now