"The C++ runtime is the owner of the local object and therefore the resource"...How can this be explained better? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

"The C++ runtime is the owner of the local object and therefore the resource"...How can this be explained better?

18th May 2020, 5:50 PM
🌹Ramar🌹
🌹Ramar🌹 - avatar
4 Answers
+ 1
Let me try to explain... You might be aware that memory is occupied from stack and heap. Heap memory is dynamic and allocated during run time.... Once you as a programmer allocate it, you have to de allocate the same...it is not handle automatically (ideally it can be de allocated when your entire program completes and execution is over but you don't wait to happen this as it might cause issue.. that's why it's good practice as a programmer to deallocate after usage) This is for dynamic memory
5th Jun 2020, 7:30 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
Now something which is not allocated dynamically is static and those are local.... You don't have to worry about it Application (you can say run time of c++) manages it automatically.. Let me take simple example: Void test () { Int a; Int* b = new int(); } Int main () { Test(); Return 0; } Here you don't have to worry about a as its local and on stack but take care of b by deleting it
5th Jun 2020, 7:33 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
I think ive got it..so in summary what you are meaning is that....It is not a necessity to deallocate the Static Memory but for Heap Memory is dynamically allocated so you have to allocate it
5th Jun 2020, 9:01 PM
🌹Ramar🌹
🌹Ramar🌹 - avatar
5th Jun 2020, 9:06 PM
🌹Ramar🌹
🌹Ramar🌹 - avatar