posix timer_create()函数导致linux内存泄漏 [英] posix timer_create() function causing memory leak on linux

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

问题描述

我在我的应用程序中使用timer_create函数的计时器功能。
当超时发生时,将创建一个新的线程。那时我的应用程序的内存使用量增加了大约11mb。我也设置了线程属性为PTHREAD_CREATE_DETACHED。任何帮助是赞赏。我还想知道在超时时创建的线程有多长时间?

I am using timer_create function for timer functionality in my application. When timeout happens, a new thread gets created. That time my application's memory usage is getting increased by around 11mb. I also have set the thread attribute to PTHREAD_CREATE_DETACHED. Any help is appreciated. I also want to know how long will the thread that gets created when timeout happens be alive?

推荐答案

我怀疑它有什么

如果你创建一个新的线程,线程需要堆栈的空间。据我所知,这个内存在线程创建时被分配一次,因为它必须是连续的。

If you create a new thread, the thread needs space for the stack. As far as I know this memory gets allocated once at thread creation because it has to be contiguous.

这听起来像是一个浪费的内存,但不是。首先,你可以降低堆栈大小,如果你想,第二:只有进程内的地址空间被分配。只有在使用堆栈时,物理内存才会被分配。

That may sound like a lot of wasted memory, but it is not. First off, you can lower the stack size if you want, second: Only the address-space inside your process gets allocated. Physical memory only gets allocated if you use the stack.

这篇关于posix timer_create()函数导致linux内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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