Skip to content

[Fix][Relax] Run destructors for non-trivially-destructible types in Arena - #20163

Open
OmarAzizi wants to merge 2 commits into
apache:mainfrom
OmarAzizi:graph-partitioner-group-leak
Open

[Fix][Relax] Run destructors for non-trivially-destructible types in Arena#20163
OmarAzizi wants to merge 2 commits into
apache:mainfrom
OmarAzizi:graph-partitioner-group-leak

Conversation

@OmarAzizi

@OmarAzizi OmarAzizi commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Summary

support::Arena never calls destructors but frees raw memory pages. GraphPartitioner::Group violates this by holding a ref counted attrs map, which leaks native memory on every pass invocation since ~Group() is never called.

Fixes #20056.

Fix

Implements option (b) from the issue: Arena::make<T>() now registers invokes a destructor for non-trivially-destructible types, guarded by if constexpr so trivially destructible types pay no extra cost. Fixes the leak at the source instead of per call site.

Went with option (b) instead of (a) as the same pattern also exists in [LiftedFunctionRewritePlan] in (rewrite_cuda_graph.cc) which would fix Group but leave that and any future case unfixed.

Testing

Reproduced the leak using the script attached to the issue (updated for the TensorStructInfo -> Type unification in #19853, otherwise unchanged): ~4.96 MiB/iter before this fix, ~0 MiB/iter after. Existing Relax fusion/partitioning tests pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][Relax] FuseOpsByPattern leaks native memory on every call (arena-allocated Group::attrs never destructed)

1 participant