quininer / per-thread-object

Efficient per-object thread-local storage implementation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Memory leak, if thread never ends

quininer opened this issue · comments

We make thread hold Rc until the thread ends. but if thread never ends, then even if all ThreadLocal<T> is released, then memory will not be released.

maybe we should make thread hold a weak reference.

We have two options to solve this problem,

  1. Release all memory when ThreadLocal<T> is dropped, but this means that destructor of thread A may be executed in thread B. This requires Send.
  2. Mark it when ThreadLocal<T> is dropped, and other threads need to actively call clean function to check value to be released.

option 2 has great limitations, so I might choose option 1.

Close by 66b2ddf