Skip to content

Fix/Fix memory leak in dygraph #17394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

JiabinYang
Copy link
Contributor

@JiabinYang JiabinYang commented May 14, 2019

Fix memory leak problem in dygraph mode and using unique_ptr to hold Variable to make sure it can be freed automatically when Varbase is released by python gc

@JiabinYang JiabinYang requested a review from sneaxiy May 14, 2019 08:56
bck_map = new BackwardSumMap();
grad_ref = new GradientRef();
bck_map = BackwardSumMap();
grad_ref = GradientRef();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines are unnecessary. BTW, it seems that it is not necessary thatbck_map and grad_ref are data member of Autograd. Just make them temporary variable inside the function.

if (grad_ref->find(vb) == grad_ref->end()) {
grad_ref->insert(std::make_pair(vb, 1));
if (grad_ref.find(vb) == grad_ref.end()) {
grad_ref.insert(std::make_pair(vb, 1));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C++ guarantees zero-initialization of primitive types. See here. You can just write ++grad_ref[vb];

BackwardSumMap* bck_map;
GradientRef* grad_ref;
BackwardSumMap bck_map;
GradientRef grad_ref;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to be data members.

Copy link
Collaborator

@sneaxiy sneaxiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent.

@JiabinYang JiabinYang changed the title Feature/sorted gradient dygraph Fix/Fix memory leak in dygraph May 17, 2019
@JiabinYang JiabinYang merged commit d7df4e5 into PaddlePaddle:develop May 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants