如何释放g_thread_init分配的内存
我想知道是否可以释放分配的内存 g_thread_init(NULL)
这是我的代码:
int main(void)
{
g_thread_init(NULL);
g_thread_exit(NULL);
}
和 valgrind 输出:
==1944== HEAP SUMMARY:
==1944== in use at exit: 8,910 bytes in 119 blocks
==1944== total heap usage: 159 allocs, 40 frees, 15,033 bytes allocated
感谢您的帮助。
I would like to know if it's possible to free the memory allocated byg_thread_init(NULL)
here is my code :
int main(void)
{
g_thread_init(NULL);
g_thread_exit(NULL);
}
and the valgrind output :
==1944== HEAP SUMMARY:
==1944== in use at exit: 8,910 bytes in 119 blocks
==1944== total heap usage: 159 allocs, 40 frees, 15,033 bytes allocated
thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
g_thread_init()
是一个运行一次的函数,用于在 GLib 中设置多线程支持。它分配的内存永远不会被释放。在较新版本的 GLib (>= 2.32) 中,
g_thread_init()
实际上是一个无操作,您根本不需要调用它——所有多线程设置都是自动完成的当你的程序启动时。所以你的问题的答案是:你不能,也不应该尝试这样做。
g_thread_init()
is a run-once function that does setup for the multithreading support in GLib. The memory it allocates is never freed.In newer versions of GLib (>= 2.32),
g_thread_init()
is effectively a no-op, and you don't need to call it at all -- all of the multithreading setup is done automatically when your program starts.So the answer to your question is: you can't, and you shouldn't be trying to.