Can any one describe Memory management in c++ in simple way | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can any one describe Memory management in c++ in simple way

new operator, delete operator and dispose()

6th Aug 2018, 4:30 PM
Samrat✌✌
Samrat✌✌ - avatar
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
6th Aug 2018, 6:36 PM
Ipang
+ 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 ..
6th Aug 2018, 5:25 PM
Ketan Lalcheta
Ketan Lalcheta - avatar