Jump to content

  • Log In with Google      Sign In   
  • Create Account

Memory Leak from Unrun Code


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 Geometrian   Crossbones+   -  Reputation: 1602

Like
0Likes
Like

Posted 26 January 2013 - 02:12 AM

Hi,
 
I've been running into a number of problems of a horribly annoying form. The general story looks like this:
 
--I run the program (developing on MSVC 2010, using CRT for memory leak checking)
--Oh noes! A memory leak!
--Nothing is obvious. Removing files/recompiling eventually tracks it down to one line in a particular file. When this line is commented, no leak. Uncommented, leak.
--But this line is never ever called. Ever. Using a debugger and putting it right before, it's obvious that it isn't.
 
How can a line that is never called cause a memory leak? I've made some silly conjectures, but really I don't know the answer.
 
Code should not be terribly relevant, but FWIW, the line that's causing the issue this time is:

menu = new QMenu();

QMenu comes from Qt 4.8.4. I've had problems with Bullet Physics though too.


What could be causing this? Thanks,
Ian


And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.

Sponsor:

#2 Khatharr   Crossbones+   -  Reputation: 3079

Like
0Likes
Like

Posted 26 January 2013 - 02:27 AM

All you've told us about is the problem itself. Without more context we have no way of knowing what's causing it.

 

If the code is indeed not being run then obviously it's not directly leaking memory, but it may be something else in that compilation unit that's screwing up the heap and removing that line simply hides the problem.


Edited by Khatharr, 26 January 2013 - 02:31 AM.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

#3 EWClay   Members   -  Reputation: 659

Like
0Likes
Like

Posted 26 January 2013 - 04:29 AM

That line does look kind of leaky though. Is menu deleted properly? Are you sure the line is not being run? Debuggers can lie sometimes. Try a full rebuild and make sure to check it in debug mode.

#4 TheChubu   Crossbones+   -  Reputation: 4827

Like
0Likes
Like

Posted 26 January 2013 - 04:46 AM

I have no idea about MSVS workings but it could be that the memory leak detector just points to a place where memory could be allocated and not de-allocated? ie, potential memory leak rather than "this is leaking while the program is running".


"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

 

My journals: dustArtemis ECS framework and Making a Terrain Generator


#5 Khatharr   Crossbones+   -  Reputation: 3079

Like
0Likes
Like

Posted 26 January 2013 - 05:50 AM

The default MSVC debugger just says that there's a leak and I think gives the address of the allocation. I'd have to mess with it to see but *effort*...

 

If you're concerned about leaks and don't want to do it the 'right' way (using STL) then you may want to check out VLD, which will give you more useful info when a leak is detected:

 

http://vld.codeplex.com/


void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

#6 C0lumbo   Crossbones+   -  Reputation: 2501

Like
0Likes
Like

Posted 26 January 2013 - 11:18 AM

My guess would be that with your line commented out the compiler is able to dead-strip swathes or even the entirety of the qt library from your project.

 

The memory leak itself might be resulting from some global constructor within the qt library that gets called when your line is present, but is stripped out when the line is not present.

 

That's just a guess though. I'd recommend you learn the tools necessary to track down memory leaks more directly rather than through trial and error. If your memory leak is reported then presumably there's some associated information, if it's only the address, then you might have some luck with a hardware breakpoint on that address of the leak which may shed some light.



#7 Aardvajk   Crossbones+   -  Reputation: 6260

Like
0Likes
Like

Posted 26 January 2013 - 11:52 AM

You could try temporarily parenting the QMenu instance to some QObject. I wouldn't be surprised if memory leak checkers get confused by Qt's object parenting system.



#8 incertia   Crossbones+   -  Reputation: 779

Like
0Likes
Like

Posted 28 January 2013 - 05:54 PM

If you want, put some messagebox before and after the call to the constructor and see if the code is run.
what

#9 Geometrian   Crossbones+   -  Reputation: 1602

Like
0Likes
Like

Posted 30 January 2013 - 04:22 PM

That line does look kind of leaky though. Is menu deleted properly? Are you sure the line is not being run? Debuggers can lie sometimes. Try a full rebuild and make sure to check it in debug mode.

If you want, put some messagebox before and after the call to the constructor and see if the code is run.

If it were run, the menu would be deleted properly--but I'm know that I'm never calling the method. I can put the "delete menu;" immediately after the allocation with the same results. "printf" shows that the code is in fact not being run (yes, being careful to flush IO buffers too).

 

you may want to check out VLD, which will give you more useful info when a leak is detected

I've used VLD before, and I've found that it sometimes doesn't pick up memory leaks. In this case, it reports "No memory leaks detected." on exit.

Actually, the problem isn't reproducible in a separate example, which, as I mentioned, points to it being some kind of problem within the application itself. I just don't know exactly what kinds of problems to look for. This:

My guess would be that with your line commented out the compiler is able to dead-strip swathes or even the entirety of the qt library from your project.

The memory leak itself might be resulting from some global constructor within the qt library that gets called when your line is present, but is stripped out when the line is not present.

That's just a guess though. I'd recommend you learn the tools necessary to track down memory leaks more directly rather than through trial and error. If your memory leak is reported then presumably there's some associated information, if it's only the address, then you might have some luck with a hardware breakpoint on that address of the leak which may shed some light.

. . . was kindof my guess, but as above the fact that the problem isn't reproduced in a simple example would seem to suggest otherwise.


And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS