From 2c06f10d3b5132752e48b473af463394fbb04047 Mon Sep 17 00:00:00 2001 From: "Lu, Teng" Date: Thu, 11 Sep 2025 18:18:34 +0800 Subject: [PATCH] Add destructor for XLAGraphExecutor to free resource. --- torch_xla/csrc/xla_graph_executor.cpp | 5 +++++ torch_xla/csrc/xla_graph_executor.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/torch_xla/csrc/xla_graph_executor.cpp b/torch_xla/csrc/xla_graph_executor.cpp index 42e38b921849..5b430810816d 100644 --- a/torch_xla/csrc/xla_graph_executor.cpp +++ b/torch_xla/csrc/xla_graph_executor.cpp @@ -122,6 +122,11 @@ XLAGraphExecutor::ComputationCache* CreateComputationCache() { } // namespace +XLAGraphExecutor::~XLAGraphExecutor() { + computation_cache_->Clear(); + delete computation_cache_; +} + auto XLAGraphExecutor::DeviceContextArena::Get() -> DeviceContextArena* { static DeviceContextArena* arena = new DeviceContextArena(); return arena; diff --git a/torch_xla/csrc/xla_graph_executor.h b/torch_xla/csrc/xla_graph_executor.h index 5e1acaa9d471..dde81aa2b74a 100644 --- a/torch_xla/csrc/xla_graph_executor.h +++ b/torch_xla/csrc/xla_graph_executor.h @@ -30,6 +30,8 @@ namespace torch_xla { class XLAGraphExecutor : public torch::lazy::LazyGraphExecutor { public: + ~XLAGraphExecutor(); + static XLAGraphExecutor* Get(); // Override to use our own DeviceContextArena.