diff --git a/paddle/framework/executor.cc b/paddle/framework/executor.cc index d50f0da03245783f8f0de481d7be0699fd10feac..1f1e4edda823d62b169422672c855d96a2bd2ede 100644 --- a/paddle/framework/executor.cc +++ b/paddle/framework/executor.cc @@ -84,8 +84,7 @@ void Executor::Run(const ProgramDesc& pdesc, Scope* scope, int block_id) { op->Run(local_scope, *device); } - // TODO(tonyyang-svail): - // - Destroy local_scope + scope->DeleteScope(&local_scope); } } // namespace framework diff --git a/paddle/framework/scope.cc b/paddle/framework/scope.cc index 5bf5e91f25ab1d920ae368eaf2000fce77d2eb07..b8e116c430d14b7079c3a464780d6cd85c8313e1 100644 --- a/paddle/framework/scope.cc +++ b/paddle/framework/scope.cc @@ -65,6 +65,13 @@ void Scope::DropKids() { kids_.clear(); } +void Scope::DeleteScope(Scope* scope) { + auto it = std::find(this->kids_.begin(), this->kids_.end(), scope); + PADDLE_ENFORCE(it != this->kids_.end(), "Cannot find %p as kid scope", scope); + this->kids_.erase(it); + delete scope; +} + framework::Scope& GetGlobalScope() { static framework::Scope* g_scope = nullptr; if (g_scope == nullptr) { diff --git a/paddle/framework/scope.h b/paddle/framework/scope.h index a7fce3514b163d78bf96b3cc19d188744a383395..78ff136ee17bb6826cf24fac00b9ad0e95fa192b 100644 --- a/paddle/framework/scope.h +++ b/paddle/framework/scope.h @@ -59,6 +59,8 @@ class Scope { /// Find the scope or an ancestor scope that contains the given variable. const Scope* FindScope(const Variable* var) const; + void DeleteScope(Scope* scope); + /// Drop all kids scopes belonged to this scope. void DropKids();