我有一个像这样的A类:
class A {
static __thread Arena * arena;
}
如果一个线程被销毁或者退出,arena占用的内存会被释放吗?
最佳答案
arena 使用的内存将被释放,但它所指向的任何内容都不会被释放。
使用 c++11 的 thread_local
和智能指针,例如
class A {
thread_local std::unique_ptr<Arena> arena;
}
关于c++ - __thread C++ 内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67717188/