pthread_create的内存泄漏 [英] pthread_create memory leak

查看:376
本文介绍了pthread_create的内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是用C语言和Linux作为我的编程平台。

I am using C language and Linux as my programming platform.

在我的应用程序,我调用pthread_create。然后,我用ps命令行工具检查我的应用程序的内存使用情况,并在VSZ列增加了4。

In my app, I call pthread_create. Then I check the memory usage of my app using ps commandline tool and it adds 4 in the VSZ column.

但问题是当pthread_create的功能处理程序退出,那是在内存中添加了4并没有释放。然后,当应用程序再次调用pthread_create的,一个4值,再次加入,直到它变得更大。

But the problem is when the pthread_create function handler exits, the 4 that was added in the memory was not release. Then when the app call the pthread_create again, a 4 value was added again until it gets bigger.

我试过在pthread_join,似乎记忆还是挺大的。

I tried pthread_join and it seems the memory still getting bigger.

感谢。

推荐答案

PS 不是衡量内存泄漏的工具。当你释放内存,你都不能保证降低进程的VSIZE,无论是由于内存碎片,从而避免不必要的系统调用。

ps is not the right tool to measure memory leaks. When you free memory, you are not guaranteed to decrease the process' vsize, both due to memory fragmentation and to avoid unnecessary system calls.

的valgrind 是一个更好的工具来使用。

valgrind is a better tool to use.

这篇关于pthread_create的内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆