Skip to content

Commit 9d40eb3

Browse files
authored
Merge pull request PaddlePaddle#11180 from jacquesqiao/cherry-pick-fix-memory-pick-to-0.13.0
fix protobuf memory leak (PaddlePaddle#11177)
2 parents 12e873b + 7fb06a5 commit 9d40eb3

File tree

2 files changed

+4
-33
lines changed

2 files changed

+4
-33
lines changed

paddle/fluid/framework/block_desc.cc

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,13 @@ void BlockDesc::Flush() {
169169
}
170170

171171
if (need_update_) {
172-
auto &op_field = *this->desc_->mutable_ops();
173-
this->ClearPBOps();
174-
op_field.Reserve(static_cast<int>(ops_.size()));
172+
this->desc_->mutable_ops()->Clear();
175173
for (auto &op_desc : ops_) {
176-
op_field.AddAllocated(op_desc->Proto());
174+
this->desc_->mutable_ops()->Add()->CopyFrom(*op_desc->Proto());
177175
}
178-
auto &var_field = *this->desc_->mutable_vars();
179-
this->ClearPBVars();
180-
var_field.Reserve(static_cast<int>(vars_.size()));
176+
this->desc_->mutable_vars()->Clear();
181177
for (auto &var_desc : vars_) {
182-
var_field.AddAllocated(var_desc.second->Proto());
178+
this->desc_->mutable_vars()->Add()->CopyFrom(*var_desc.second->Proto());
183179
}
184180
need_update_ = false;
185181
}
@@ -217,22 +213,6 @@ BlockDesc::BlockDesc(const BlockDesc &other, proto::BlockDesc *desc,
217213
}
218214
}
219215

220-
void BlockDesc::ClearPBOps() {
221-
auto ops = this->desc_->mutable_ops();
222-
while (!ops->empty()) {
223-
// we do not own the OpDesc, so release the ownership.
224-
ops->ReleaseLast();
225-
}
226-
}
227-
228-
void BlockDesc::ClearPBVars() {
229-
auto vars = this->desc_->mutable_vars();
230-
while (!vars->empty()) {
231-
// we do not own the VarDesc, so release the ownership.
232-
vars->ReleaseLast();
233-
}
234-
}
235-
236216
void BlockDesc::SetForwardBlockID(int32_t forward_block_id) {
237217
PADDLE_ENFORCE(!desc_->has_forward_block_idx(),
238218
"Parent block ID has been set to %d. Cannot set to %d",

paddle/fluid/framework/block_desc.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ class BlockDesc {
4141

4242
BlockDesc(const BlockDesc &other, proto::BlockDesc *desc, ProgramDesc *prog);
4343

44-
~BlockDesc() {
45-
this->ClearPBVars();
46-
this->ClearPBOps();
47-
}
48-
4944
int32_t ID() const { return desc_->idx(); }
5045

5146
int32_t Parent() const { return desc_->parent_idx(); }
@@ -113,10 +108,6 @@ class BlockDesc {
113108

114109
ProgramDesc *Program() const { return this->prog_; }
115110

116-
private:
117-
void ClearPBOps();
118-
void ClearPBVars();
119-
120111
private:
121112
ProgramDesc *prog_; // not_own
122113
proto::BlockDesc *desc_; // not_own

0 commit comments

Comments
 (0)