+ 1
"The C++ runtime is the owner of the local object and therefore the resource"...How can this be explained better?
4 odpowiedzi
+ 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
+ 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
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
0
Thanks Ketan Lalcheta