Hi everyone! I would like to save/memorize a tensor in one class.
Here is my code snip:
class A {
public:
void func(const torch::Tensor &input) {
t = new torch::Tensor(at::empty_like(input));
}
~A() {
if (t) {
delete t;
t = nullptr;
}
}
torch::Tensor *t = nullptr;
};
or
class B {
public:
void func(const torch::Tensor &input) {
t = at::empty_like(input);
}
~B() {
// Could I need to do something else to forget the tensor?
}
torch::Tensor t;
};
Or is there any other way to prevent running out of memory?
How can I do that correctly? Hope for your help!