Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

strange memory problems 1

Status
Not open for further replies.

piofenton

Instructor
Jul 12, 2002
33
IE
Hi all,
I have a program which when run, causes a detected memeory leak at almost every line. I am using the CRT library to help me identify the leaks and my ouput window produces somnething like this continously
Detected memory leaks!
Dumping objects ->
{163170} normal block at 0x00FBB8A0, 8 bytes long.
Data: < > 05 00 00 00 07 00 00 00
{163169} normal block at 0x00FBB858, 8 bytes long.
Data: < > 02 00 00 00 01 00 00 00
{163168} normal block at 0x00FBB810, 8 bytes long.
Data: < > 01 00 00 00 09 00 00 00
{163167} normal block at 0x00FBB7C8, 8 bytes long.
Data: < > 06 00 00 00 08 00 00 00

it literaly never ends....
Why would this be happening. Unhelpfully, even though I have followed instructuions, double clicking on a detected memorl leak does not lead me to the position in code where it occurs.
Can anyone help me. I'm at my wits end!!
 
you can get a clue at the beginning of the text you have entered above - there will be a few lines of text that usually contains some info that will point you in the right direction? (i.e. the lines around the line "Memory Leaks Detected" (or something like that))
 
thanks Shetlandbob,
I'm also using glowcode to identify leaks, and it identifies none while performing all other profilinng quiet well, whereas Microsoft vis studio spots loads of memory leaks. Which should I believe I wonder!

Maybe I need this explained to me properly. I thousands of lines of unyieldy code which performs its function properly, but when running, it gobbles up memory (according to the task manager) quiet steadily but in small amouonts. I have checked all my allocations to see if there is a mathcing deallocation. Invariably there is. Unfortunatley I run out of Virtual memory most of the time. Even if I don't, the program some how manages to appear to go to sleep, and while the CPU is idle it performs no computation! Why would this happen? I am baffled!
 
{163170} normal block at 0x00FBB8A0, 8 bytes long.
Data: < > 05 00 00 00 07 00 00 00

Looks like pairs of integers to me - 5,7 in this case.
Try to match up data you see here with data you process, then locate in the code where that data is handled.

Look for say
int *p = new int[2];

without a corresponding delete.

> it gobbles up memory (according to the task manager) quiet steadily but in small amouonts.
Are you using "traditional" VC6 C++, or are you using "managed" VC7.NET C++ ?
VC6 - go with the memory leak
VC7 - blame lazy garbage collection. You should get it back when you really need it.

--
 
Thanks for the tips there Salem
I am using Visual studio.net C++ but without "managed extensions". Does this mean it is unmanaged?
If yes am I somewere between a memory leak and lazy garbage collection?
 
If it's unmanaged, then I believe it really is leaking memory.

As far as I know, only managed code benefits from a garbage collection, because I think you have to edit the code to indicate which objects you allocate can be garbage collected (though don't quote me on that).


--
 
Thanks Salem, I must admit it most likely is a memory managment problem but one that is hard to track.
On a related issue, if a program runs out of physical memory what is its most likely reaction??
 
I had a program, which steady caused memory leaks under Windows, but ran correctly under Linux.
 
piofenton said:
if a program runs out of physical memory what is its most likely reaction

I think it starts using "swap space". i.e. it writes memory to disk temporarily
 
If a 2d array is allocated memory in this fashion, how should it be deleted?

MyObject **lastJobs, **lastMachines ;
lastJobs = new MyObject*[getNbJobs()] ;
lastMachines = new MyObject*[getGreatestMachineNb()] ;

does this suffice:

delete[] lastJobs;
delete[] lastMachines;
 
> lastJobs = new MyObject*[getNbJobs()] ;
Well if you do
Code:
lastJobs = new MyObject*[getNbJobs()] ;
for ( int i = 0 ; i < getNbJobs() ; i++ ) {
    lastJobs[i] = new MyObject;
}

Then you also need to delete them
Code:
for ( int i = 0 ; i < getNbJobs() ; i++ ) {
    delete lastJobs[i];
}
delete [] lastJobs

Simply deleting the top-level object does not cause all its internal dependencies to be deleted automatically.

If you don't do this, I'd say this is your memory leak.

--
 
thanks again Salem,
As it happens this is the next line of code. Memory is not being allocated here in this instance, or at any point further down the code. (this is some code which I am tryin to interpet myself, it was written by another). This aspect of it seems non sensical!

for (i = 0 ; i < getNbJobs() ; i++)
lastJobs = 0 ;
 
Well that by itself is not a problem - in fact making sure all the pointers are NULL is a good idea.

If the whole thing is never used, then I'd remove it from the code.

Are you sure lastJobs isn't passed as a parameter to some other function?

--
 
Thank you al;l for your advice in the last few days on this issue. I'm glad to report that I have fixed the memory leak problems which I had.
Cheers
P.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top