c++ - Is delete[] equal to delete? -


ip_adapter_info *ptr=new ip_adapter_info[100]; 

if free using

delete ptr; 

will lead memory leak, if not why ?

this disassembly code generated 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 leads memory leak, wipes hard disk, gets pregnant, makes nasty nasal demons chasing around apartment, or lets work fine no apparent problems, undefined. might way 1 compiler, , change another, change new compiler version, each new compilation, moon phases, mood, or depending on number of neutrinos passed through processor on last sunny afternoon. or might not.

all that, , infinite number of other possibilities put 1 term: undefined behavior:

just stay away it.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -