-
Notifications
You must be signed in to change notification settings - Fork 179
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
fix memleak #69
fix memleak #69
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class defer
seems to be duplicating the function of std::unique_ptr
. I don't know how @serizba feels about it.
Emm... It's not really the same thing. defer is more general. |
I am mostly neutral (though slightly negative) on the defer class here,
because it can be implemented using std::unique_ptr without too much
complication. However, I like defer as a general cleanup as in golang.
…On Sat, Nov 7, 2020, 03:00 Allen ***@***.***> wrote:
Class defer seems to be duplicating the function of std::unique_ptr. I
don't know how @serizba <https://github.com/serizba> feels about it.
Emm... It's not really the same thing. defer is more general.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#69 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AALDTHWKZDK4GO6SQK75NEDSOT5A3ANCNFSM4TNPMYCA>
.
|
I do not have a strong opinion on the topic either. I will accept the request if you both agree on it. If you think that just using |
@ivanallen I am sorry that I didn't get much time to test this, my apologies. The other @serizba I think this is good to go. Although gcc's leak sanitizer still shows leaks in libcuda.so, I think it is false positive. If you still prefer
|
I list the difference between
std::vector<TF_Tensor*> inp_val(inputs.size());
+ defer d([&inp_val]{
+ for (auto* tf_tensor : inp_val) TF_DeleteTensor(tf_tensor);
+ });
+ std::vecotr<std::unique_ptr<TF_Tenosr, decltype(&TF_DeleteTensor)>> inp_val_ptr;
std::vector<TF_Tensor*> inp_val(inputs.size());
//...
for (...) {
// ...
auto inp_tensor = TFE_TensorHandleResolve(std::get<1>(inputs[i]).tfe_handle.get(), context::get_status());
+ inp_val_ptr.emplace_back(inp_tensor, TF_DeleteTensor);
+ inp_val[i] = inp_tensor; // copy raw pointer to anther vector
}
//... |
I think @serizba should be the person to make the final decision here :) |
Thanks for showing both options @ivanallen, Now I think that perhaps using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New problems will be resolved in a new pull request.
Fix memory leak.