Sunday, August 30, 2009

memory leak

will the following code lead to memory leak? if so how would you write a code that does not leak memory


char* str=new char[30];
delete str;

click here for answer


If you want to delete an array, use
delete [] str;
other wise delete str just deletes the pointer memory not the array memory of 30 bytes thus leading to memory leak.

1 comment: