[英]When does Eigen matrix release heap memory?
I would like to write a very very tiny matrix/tensor library with minimal features, and API like Eigen.我想编写一个非常小的矩阵/张量库,具有最少的功能,以及像 Eigen 一样的 API。
What confused me is, setting a debug break point, does not take me into some destructor function, I get nothing.让我感到困惑的是,设置调试断点并没有带我进入一些析构函数 function,我什么也没得到。
To reproduce, use this snippet that uses Eigen:要重现,请使用这个使用 Eigen 的片段:
#include <Eigen/Dense>
#include <stdio.h>
#include <iostream>
using namespace Eigen;
int main()
{
printf("hello Eigen\n");
{
MatrixXf m1(300, 400);
MatrixXf m2(300, 400);
MatrixXf m3 = m1 + m2;
std::cout << m3.rows() << std::endl;
printf("bye\n");
} // set a debug break point in this line, expecting going into its destructor and free memory, but there isn't
printf("-----------------\n");
return 0;
}
As a comparison, I simple created a Tensor template class, and when leaving its scope, its destructor is called:作为对比,我简单地创建了一个张量模板 class,离开它的 scope 时,它的析构函数被调用:
template<class T>
class Tensor {
public:
int c, h, w;
int len;
T* data;
Tensor(int _c, int _h, int _w): c(_c), h(_h), w(_w) {
len = c * h * w;
data = new T[len];
}
~Tensor() {
if (data) {
free(data);
}
}
};
int main() {
// Tensor
{
printf("hello tensor\n");
Tensor<float> tensor(3, 2, 2);
printf("bye tensor\n");
} // set a debug break point here, Tensor class's destructor is called
return 0;
}
My question: when and where does Eigen's big matrix (with heap memory allocated) free its heap memory?我的问题:Eigen 的大矩阵(分配了堆 memory)何时何地释放其堆 memory? And how can I see that?我怎么能看到呢?
update: I forget to mention that I was using Visual Studio 2019 Debug mode.更新:我忘了提到我使用的是 Visual Studio 2019 调试模式。
This is the compiler and debugger difference, after tried difference tools and methods from comments in this problem description.这是编译器和调试器的区别,在尝试了此问题描述中注释中的不同工具和方法后。
The Visual Studio 2019 (until 2021-4-9, version 16.9.3) still can't debug step into DenseStorage class's destruction function. Visual Studio 2019(直到 2021-4-9,版本 16.9.3)仍然无法调试进入 DenseStorage 类的破坏 function 的步骤。
While, Visual Studio 2019 with clang-cl, and lldb/gdb with clang-10/g++-9.3 on Linux, all can debug into DenseStorage class's destruction function.而在 Linux 上带有 clang-cl 的 Visual Studio 2019 和带有 clang-10/g++-9.3 的 lldb/gdb 都可以调试到 DenseStorage 类的破坏 function。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.