如何释放g_thread_init分配的内存

发布于 2024-12-20 15:17:07 字数 393 浏览 3 评论 0原文

我想知道是否可以释放分配的内存 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 by
g_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薆情海 2024-12-27 15:17:07

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文