Feature/free kid scope (#4951)

* Delete kid

* Delete local scope
revert-4814-Add_sequence_project_op
Yu Yang 8 years ago committed by GitHub
parent 42f2dd4041
commit af4dac4ac3

@ -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

@ -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) {

@ -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();

Loading…
Cancel
Save