-
Notifications
You must be signed in to change notification settings - Fork 21
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
Address memory leak in overloaded operators #297
Conversation
Since the current best practice still works fine, I think we can defer mentioning the destructor here and put some text on that in the upcoming tensor docs in #291. |
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.
Yep, we discussed at length together yesterday and located the nullification together so I am happy with the concepts and approach.
A couple of non-blocking queries so happy for this to merge when ready.
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.
Consider renaming test_tensor_constructors_destructors.pf
?
Also I get why you test empty and delete in a single subroutine but would it be relatively straightforward to separate them to try and keep things monotised (is that a word...?)?
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.
Closes #295.
This PR makes
torch_tensor_delete
the destructor for thetorch_tensor
class. This means that it gets called automatically when a tensor goes out of scope. I've set it up such that the user may still call the subroutine explicitly if they wish, but this is no longer required.I also changed the overloaded operators so that inputs and outputs to the C++ functions are all pointers, meaning that only the empty/zeros/ones/blob/array constructors create new
torch::Tensor
objects on the C++ side. The overloaded operators now merely operate on values for the data associated with the tensors they point to.