1

我正在开发一个需要创建和删除大量线程的软件。

当我创建一个线程时,内存会增加,当删除它们时(通过使用命令确认ps -mo THREAD -p <pid>),与程序/软件相关的内存不会减少(top 命令)。结果我的内存用完了。

我已经使用 Valgrind 检查内存错误/泄漏,但找不到任何内容。这是在一个Debian盒子上。请让我知道问题可能是什么。

4

2 回答 2

0

你是如何删除线程的?这里的注释http://www.kernel.org/doc/man-pages/online/pages/man3/pthread_join.3.html谈到在某些情况下需要调用 join 来释放资源。

于 2012-08-08T11:04:09.377 回答
0

You do not run out of memory.

The "free memory" you see in top command is actually not the memory that is available when required. Linux kernel uses as much as possible/useable of the free memory for its page cache. When a process requires memory, the kernel can throw away that page cache and provide that memory to a process.

In other words: linux uses the free memory, instead of just leaving it idling around...

Use free -m: In the row labeled "-/+ buffers/cache:" you will see the real amount of memory available for processes.

于 2012-08-08T11:23:06.630 回答