Is delete[] equal to delete?(delete[] 是否等于删除?)
问题描述
IP_ADAPTER_INFO *ptr=new IP_ADAPTER_INFO[100];
如果我免费使用
delete ptr;
会不会导致内存泄露,如果不是那为什么?
will it lead to memory leak, if not then why ?
这是VS2005生成的反汇编代码
This is disassembly code generated by VS2005
; delete ptr;
0041351D mov eax,dword ptr [ptr]
00413520 mov dword ptr [ebp-0ECh],eax
00413526 mov ecx,dword ptr [ebp-0ECh]
0041352C push ecx
0041352D call operator delete (4111DBh)
00413532 add esp,4
; delete []ptr;
00413535 mov eax,dword ptr [ptr]
00413538 mov dword ptr [ebp-0E0h],eax
0041353E mov ecx,dword ptr [ebp-0E0h]
00413544 push ecx
00413545 call operator delete[] (4111E5h)
0041354A add esp,4
推荐答案
这是否会导致内存泄漏、擦除硬盘、让你怀孕、让讨厌的鼻魔在你的公寓周围追赶你,或者让一切正常没有明显的问题,是未定义的.一个编译器可能会这样,另一个编译器会改变下午.或者它可能不会.
Whether this leads to a memory leak, wipes your hard disk, gets you pregnant, makes nasty Nasal Demons chasing you around your apartment, or lets everything work fine with no apparent problems, is undefined. It might be this way with one compiler, and change with another, change with a new compiler version, with each new compilation, with the moon phases, your mood, or depending on the number of neutrinos that passed through the processor on the last sunny afternoon. Or it might not.
所有这些,以及无数其他可能性都归为一个术语:未定义的行为:
All that, and an infinite number of other possibilities are put into one term: Undefined behavior:
远离它.
这篇关于delete[] 是否等于删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:delete[] 是否等于删除?
基础教程推荐
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- CString 到 char* 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
