__thread c++ memory leak

Viewed 93

I have a class A like this:


class A {
  static __thread Arena * arena;
}

if one thread is destroyed or just quit , will the memory which arena take will be released?

1 Answers

The memory used by arena will be released but whatever it is pointing to won't be freed.

Use c++11's thread_local with a smart pointer instead e.g.

class A {
  thread_local std::unique_ptr<Arena> arena;
}
Related