DEFINE_THREAD_SAFE_STATIC_LOCAL leaks objects per thread. |
||
Issue descriptionEach time a thread accesses a DEFINE_THREAD_SAFE_STATIC_LOCAL, it will leak an object: https://cs.chromium.org/chromium/src/third_party/blink/renderer/platform/wtf/std_lib_extras.h?type=cs&q=DEFINE_THREAD_SAFE_STATIC_LOCAL&sq=package:chromium&g=0&l=46 If a process creates an destroys threads dynamically [and the threads access the variable], this will cause an unbounded memory leak over time. I suspect this will mostly affect the task scheduler [if it ever ends up making/destroy thread dynamically]. We should get rid of the macro. It's possible to accomplish the same behavior without leaking in a few lines of code: e.g. """ base::ThreadLocalStorage::Slot& ShimStateTLS() { static base::NoDestructor<base::ThreadLocalStorage::Slot> shim_state_tls( &DestructShimState); return *shim_state_tls; } ShimState* GetShimState() { ShimState* state = static_cast<ShimState*>(ShimStateTLS().Get()); if (!state) { state = new ShimState(); ShimStateTLS().Set(state); } return state; } """
,
Jun 29 2018
Oh sorry, misread. DEFINE_THREAD_SAFE_STATIC_LOCAL doesn't have to do with TLS at all.
,
Jul 9
Re. "I suspect this will mostly affect the task scheduler [if it ever ends up making/destroy thread dynamically]." Task scheduler already *does* create/destroy threads dynamically. Is DEFINE_THREAD_SAFE_STATIC_LOCAL ok after all (re. #2)? |
||
►
Sign in to add a comment |
||
Comment 1 by npm@chromium.org
, Jun 29 2018Components: Blink>Internals>WTF