Problem usage memory in C

后端 未结 5 1225
说谎
说谎 2020-12-01 23:06

Please help :) OS : Linux

Where in \" sleep(1000);\", at this time \"top (display Linux tasks)\" wrote me 7.7 %MEM use. valgrind : not found memory leak.

I u

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-01 23:44

    If you're trying to establish whether your program has a memory leak, then top isn't the right tool for the job (valrind is).

    top shows memory usage as seen by the OS. Even if you call free, there is no guarantee that the freed memory would get returned to the OS. Typically, it wouldn't. Nonetheless, the memory does become "free" in the sense that your process can use it for subsequent allocations.

    edit If your libc supports it, you could try experimenting with M_TRIM_THRESHOLD. Even if you do follow this path, it's going to be tricky (a single used block sitting close to the top of the heap would prevent all free memory below it from being released to the OS).

提交回复
热议问题