From 5d01c96ab74b155c7601c56f4a810224ee4703db Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Wed, 7 Dec 2022 16:48:47 -0500 Subject: [PATCH 1/2] Clean closure and task-local-state in jl_finish_task --- src/task.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/task.c b/src/task.c index a5ebc1ce26005..306dc8477c381 100644 --- a/src/task.c +++ b/src/task.c @@ -308,6 +308,11 @@ void JL_NORETURN jl_finish_task(jl_task_t *t) ct->ptls->in_pure_callback = 0; ct->world_age = jl_atomic_load_acquire(&jl_world_counter); // let the runtime know this task is dead and find a new task to run + + // Empty out the closure and the task local state so that GC can free those values. + ct->start = jl_nothing; + ct->tls = jl_nothing; + jl_function_t *done = jl_atomic_load_relaxed(&task_done_hook_func); if (done == NULL) { done = (jl_function_t*)jl_get_global(jl_base_module, jl_symbol("task_done_hook")); From 740bc1848f59f36f4cfa65da801660b9e27250a3 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Thu, 8 Dec 2022 10:00:27 -0500 Subject: [PATCH 2/2] fixup! Clean closure and task-local-state in jl_finish_task --- stdlib/Serialization/test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/Serialization/test/runtests.jl b/stdlib/Serialization/test/runtests.jl index 46749d4375538..f19cb160a8f85 100644 --- a/stdlib/Serialization/test/runtests.jl +++ b/stdlib/Serialization/test/runtests.jl @@ -358,7 +358,7 @@ create_serialization_stream() do s # user-defined type array serialize(s, t) seek(s, 0) r = deserialize(s) - @test r.storage[:v] == 2 + @test r.storage == nothing @test r.state === :done @test r.exception === nothing end