# How to clear out buffers stored in \`task\_local\_storage\`

**URL:** <https://discourse.julialang.org/t/how-to-clear-out-buffers-stored-in-task-local-storage/100079>\
**Category:** General Usage\
**Tags:** question, task\_local\_storage\
**Created:** [June 9, 2023, 2:34am UTC](https://discourse.julialang.org/t/how-to-clear-out-buffers-stored-in-task-local-storage/100079 "2023-06-09T02:34:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [June 9, 2023, 2:34am UTC](https://discourse.julialang.org/t/how-to-clear-out-buffers-stored-in-task-local-storage/100079/1 "2023-06-09T02:34:58Z")

</div>

Before, the buffer is inside my struct and those are reclaimed whenever objects are GC-ed.

If I used task\_local\_storage, the buffer would accumulate infinitely on the main task, should I use `finalize()` to clear out the `task_local_storage()[key]` manually? Or we don’t know the fianlizer will always be on the main task?

(the other tasks I don’t have to worry about because their task local storage will be cleared out when they get GC-ed)

---

<div class="post-metadata">

**Author:** ![vchuravy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vchuravy/32/8_2.png) [@vchuravy](https://discourse.julialang.org/u/vchuravy)\
**Post date:** [June 9, 2023, 4:11am UTC](https://discourse.julialang.org/t/how-to-clear-out-buffers-stored-in-task-local-storage/100079/2 "2023-06-09T04:11:44Z")

</div>

Yeah finalizers can run on any task.

Nothing really great comes to mind. Weak refs might be an option, but they aren’t great.

One option is to provide an explicit clear function…

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [June 9, 2023, 12:15pm UTC](https://discourse.julialang.org/t/how-to-clear-out-buffers-stored-in-task-local-storage/100079/3 "2023-06-09T12:15:58Z")

</div>

> [@vchuravy](#):
>
> One option is to provide an explicit clear function…

not the worst design I suppose…
