Deallocate workspace on thread exit (#102276)
LeakSanitizer picks up this allocation as a leak, so turn the buffer and size into a single object that deallocates when the thread_local is destroyed.
Note that in our use case the call that hits this code is running on a separate thread(s) which can, under the right circumstances, be torn down and rebuilt hence leaking multiple instances of this allocation.
Testing was performed locally on an Apple M2 with this patch applied and the ~100MB of leaks previously shown by LeakSanitizer and Instruments are no longer there.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/102276
Approved by: https://github.com/ezyang