Solved

Detected memory leaks!

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ODBC Connection Logging, ADO.NET 6 64
sameEnds challenge 3 156
only14 challenge 19 75
how to split multiple lines delimiter : 8 97
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

813 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

9 Experts available now in Live!

Get 1:1 Help Now