Closed 1046099253 closed 1 year ago
现象:在线程生命周期内使用LOG打印日志,线程释放后出现内存泄露
定位:问题可能是TLS使用指针造成的,线程释放后并不会调用析构函数
inline fastream& log_stream() { static __thread fastream* s = 0; return s ? *s : *(s = co::_make_static<fastream>(256)); } inline ThreadAlloc* talloc() { static __thread ThreadAlloc* ta = 0; return ta ? ta : (ta = make_thread_alloc()); }
频繁创建、销毁线程是设计上的错误。使用了 TLS 的内存分配器,一般不能在线程退出时释放资源,一个线程分配的内存,可能被其他线程使用。
感谢回复,频繁创建、销毁线程确实是设计上的错误。
现象:在线程生命周期内使用LOG打印日志,线程释放后出现内存泄露
定位:问题可能是TLS使用指针造成的,线程释放后并不会调用析构函数