开发者

help required regarding memory leak

my application is causing memory leak of 10mb when the first timeout occurs. Heare i am using linux timer functions (timer_create etc.,).

For the subsequent timeouts no issue is there. I doubt some problem with linux timers.

I debugged it with valgrind and purify. Even these tools are of no help to me. In both the tools, memory leaked is shown as few kb's. But my application is causing memory leak of 10mb for the first timeout.

If anybody fac开发者_如何学编程ed this problem earlier, please help me.


To find out which bits of you code is causing the leak (if any), compile your code to include debug symbols (i.e. include -g flag if you're using gcc), then run your program via valgrind.

valgrind --leak-check=full ./your_program

The run will take a little longer than usual, but when your program ends, the output from valgrind should tell you how much memory you've leaked and where the cuplrits are.

Sample output:

==10934== HEAP SUMMARY:
==10934==     in use at exit: 10 bytes in 10 blocks
==10934==   total heap usage: 10 allocs, 0 frees, 10 bytes allocated
==10934== 
==10934== 10 bytes in 10 blocks are definitely lost in loss record 1 of 1
==10934==    at 0x4024F20: malloc (vg_replace_malloc.c:236)
==10934==    by 0x8048402: main (a.c:8)
==10934== 
==10934== LEAK SUMMARY:
==10934==    definitely lost: 10 bytes in 10 blocks
==10934==    indirectly lost: 0 bytes in 0 blocks
==10934==      possibly lost: 0 bytes in 0 blocks
==10934==    still reachable: 0 bytes in 0 blocks
==10934==         suppressed: 0 bytes in 0 blocks

update

Since you're already using valgrind, perhaps you could try using the Massif tool that comes with it. It should be able to paint a more accurate picture of memory usage (compare to simply watching top).

Check out this tutorial to see how it can be used. You may need some additional options to get a sensible graph depending on the runtime and mem usage of your program. Some useful options are described a few pages later in the tutorial.

Good luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜