Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ TheIDE » U++ TheIDE: Compiling, Linking, Debugging of your packages » Getting "heap leaks detected!" error messages on program exit. How to debug it?
Getting "heap leaks detected!" error messages on program exit. How to debug it? [message #3980] Thu, 13 July 2006 14:52 Go to next message
battika is currently offline  battika
Messages: 4
Registered: July 2006
Location: Budapest, Hungary
Junior Member
Sorry for the rather noobish question I'm still familiarizing myself with U++.

I'd like to connect to a Postgres database from the latest Ulimate++ running on Red Hat Linux ES 4 (Nahant) and just downloaded the precompiled libpqxx Postgres files to give them a go. I've managed to set up the connection to the Postgres server but upon program exit I always get a "heap leak detected!" error message". Even when I build an empty console project with libqxx.so linked I get the same message. Can you give me pointer where I should start looking at this issue, and is it an issue anyway?

Thanks in advance.
Re: Getting "heap leaks detected!" error messages on program exit. How to debug it? [message #3986 is a reply to message #3980] Thu, 13 July 2006 18:04 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12697
Registered: November 2005
Ultimate Member
Well, hunting memory leaks is always troublesome, that is why you should hunt one as soon as possible Wink

Now if heap leak manifests when connecting to external library, it is even more puzzling... (have you any 'new' in your code?)

Anyway, for U++ based code, I usually start with looking at log file, which dumps all leaks. Quite often you can tell what the leak is just examining it.

If that does not help, there is one ugly hack in heap code - you can add "memory-watch" into your APP_MAIN to catch the allocation that returns the address the leaks. (see Core/dbgheap.cpp for details - you place breakpoint there to catch). That of course helps only as long as leaking allocation for the specific address is the first one...

Then of course, if everything else fails, I usually start to "minimize" code, removing part after part until leak goes away (then the bug is in the part I removed).

Hopefuly, not considering the low level stuff, leak incidence in U++ is low. Hint: The most common cause of memory leak in my code is missing virtual destructor in the base class...

Mirek
Re: Getting "heap leaks detected!" error messages on program exit. How to debug it? [message #3995 is a reply to message #3986] Thu, 13 July 2006 22:44 Go to previous messageGo to next message
battika is currently offline  battika
Messages: 4
Registered: July 2006
Location: Budapest, Hungary
Junior Member
Hi Mirek,

First of all, thank you for your prompt and detailed answer. I hope you're still not running out of patience as I have some more comments. Rolling Eyes


Quote:

Now if heap leak manifests when connecting to external library, it is even more puzzling... (have you any 'new' in your code?)

Actually I started off with a "core console project". Included the Postgres library header files and added the library to the linker. Now if I comment out *everything* so only the CONSOLE_APP_MAIN section remains with the #include statement and attempt to run the program I get the same error message. So to answer your question I don't have any new()'s in my code since I don't have a code Surprised

Quote:

Anyway, for U++ based code, I usually start with looking at log file, which dumps all leaks. Quite often you can tell what the leak is just examining it.


Thank you for the tip. Again, sorry for the question but can you tell me where the log is normally located (Linux)?

Quote:

If that does not help, there is one ugly hack in heap code - you can add "memory-watch" into your APP_MAIN to catch the allocation that returns the address the leaks. (see Core/dbgheap.cpp for details - you place breakpoint there to catch). That of course helps only as long as leaking allocation for the specific address is the first one...


Cool, I will do that.

Quote:

Then of course, if everything else fails, I usually start to "minimize" code, removing part after part until leak goes away (then the bug is in the part I removed).


My code is already minimized Laughing . Probably it's time to have a look at the third-party header files.

Thanks a lot for your help again.

Re: Getting "heap leaks detected!" error messages on program exit. How to debug it? [message #3997 is a reply to message #3995] Fri, 14 July 2006 09:31 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12697
Registered: November 2005
Ultimate Member
Log in linux is located in ~, named .upp.log (if it was created before APP_MAIN) or .myapp.log otherwise.

There is of course possible that there is bug in Linux/U++ code that causes the leak... What version of U++ are you using?

Have you tried any U++ examples?

Then it is possible that postgress itself leaks by header (yes, I can imagine that if it is C++ code). (is it?)

BTW, postgress still lacks U++ support. Maybe you will be able to create one in process Wink

Mirek
Re: Getting "heap leaks detected!" error messages on program exit. How to debug it? [message #4002 is a reply to message #3997] Fri, 14 July 2006 13:44 Go to previous messageGo to next message
battika is currently offline  battika
Messages: 4
Registered: July 2006
Location: Budapest, Hungary
Junior Member
U++ examples are working fine. I'm using the latest stable release (605). So it must be something with the third-party Postgres header files. I will do my best to get this issue fixed and I'm obviously happy to contribute the process to the U++ community. Thanks a lot.
Re: Getting "heap leaks detected!" error messages on program exit. How to debug it? [message #12274 is a reply to message #3986] Tue, 23 October 2007 02:55 Go to previous message
nixnixnix is currently offline  nixnixnix
Messages: 415
Registered: February 2007
Location: Kelowna, British Columbia
Senior Member
Hi,

If anyone else, like me, found this thread and wondered what Mirek's advice meant regarding the "hack", please see this thread for more details on how to hunt down memory leaks.

http://www.ultimatepp.org/forum/index.php?t=tree&th=440& amp; amp; amp; amp;

The place to put your breakpoint is now somewhere around line 82 - 85 of heapdbg.cpp and you can just copy and paste your MemoryWatch statements from your buglog into your GUI_APP_MAIN{}

Cheers,

Nick

p.s. Oh wow! I just realised what has been done to the debug windows (not been in 710-dev1 for long and not been able to step through for a while). The IDE just gets more and more powerful!

[Updated on: Tue, 23 October 2007 03:43]

Report message to a moderator

Previous Topic: Again about packages
Next Topic: Problems with debugging in TheIDE (mingw)
Goto Forum:
  


Current Time: Fri Sep 18 12:12:58 CEST 2020

Total time taken to generate the page: 0.01540 seconds