diff --git a/paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc b/paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc index 513b5f5cb3f879c3f6c2f4da7eea8fc64c6266aa..87def83ac507e251057b49ce21368f70a1154175 100644 --- a/paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc +++ b/paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc @@ -844,6 +844,22 @@ void BuildOpFuncList(const platform::Place& place, interpreter::LogDeviceMemoryStats(place); } } + + // in the unused_var_map, we did not record the variable who are created in + // ApplyDataTransform. So we erase these variables here. + std::deque>* garbages = + new std::deque>(); + for (const auto& transferred_var : var_scope->DataTransferAddedVars()) { + const auto& var_name = transferred_var.first; + auto* var = local_scope->FindVar(var_name); + if (var == nullptr) continue; + VLOG(6) << "Erase variable " << var_name; + if (var->IsType()) { + garbages->emplace_back( + var->GetMutable()->MoveMemoryHolder()); + } + } + delete garbages; } void BuildVariableScope(const framework::BlockDesc& block,