c++ - 无法释放给定 Maya 类型的内存

标签 c++ memory maya

在C++中,我可以预留一些内存然后删除这 block 内存,比如:

float *myFloat;
myFloat = new float[10];
delete myFloat;  --> Works fine

但是,如果类型不是 float * 而是 MTransformationMatrix *(Maya 类型),那么我无法删除:

MTransformationMatrix *myTransformationMatrixes;
myTransformationMatrixes = new MTransformationMatrix[10];
delete myTransformationMatrixes;   --> Crash

为了释放内存,我需要为特殊类型做些什么吗?

最佳答案

这两个分配的对象都是数组,你应该使用delete[]语法来删除它们:

float *myFloat = new float[10];
delete[] myFloat;

MTransformationMatrix *myTransformationMatrixes;
myTransformationMatrixes = new MTransformationMatrix[10];
delete[] myTransformationMatrixes;

你的两个例子都调用了未定义的行为,你很幸运,第一个没有造成明显的伤害。

关于c++ - 无法释放给定 Maya 类型的内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35080660/

相关文章:

python - 如何从 Maya 中启动 Nuke?

python - Maya python 连接选择的属性

c++ - 在 C/++ 上的只读共享内存中具有输入图的图算法 (lib)

c++ - 复制初始化和直接初始化有区别吗?

c++ - 如何通过在逗号后打断来制作 clang 格式换行函数?

c++ - 内存冲突 : SIGSEGV and 'can' t find linker symbol for virtual table. ..'

c++ - 没有 "visible"DC 的 HBITMAP 上的 DrawText?

java - 将大量数据加载到内存时会增加 permsize

c++ - C++ 中 void 函数和非 void 函数的区别

python - 动态创建变量名