0
Can any one describe Memory management in c++ in simple way
new operator, delete operator and dispose()
2 Answers
+ 3
dispose apparently is only known/used in "managed" C++. Here's a documentation of IDisposable.Dispose:
https://msdn.microsoft.com/en-us/library/system.idisposable.dispose(v=vs.110).aspx
+ 2
Samratââ
there is two type of memory..static and dynamic...
let's talk about static memory first.. once you create any variable of fix size (for example, int a or int array[5]); compiler allocates memory in stack ..this gets destroy once your scope of variable ends... no management is required to destroy this memory by coder...
now coming to dynamic memory, it's allocated by user based on requirement with new operator... its dynamic memory ... if you are not sure how many int you need for array, you do it like int* pArr = new int [n]... with this , you gets Dynamically allocated memory in heap for n number of int.. compiler just allocates pointer to first member of allocated memory block of n int.. pointer destroys automatically when scope ends...but you should destroy new allocated memory with delete operator from heap...
I have not used dispose ..