Deallocating dynamically allocated heap
When i am dynamically allocating memory (heap) in a program, and in this case if i am not making an explicit deallocation call or free() call then when will this dynamicaaly allocated heap will get deallocated.Is it at the end of program or is it at the end of c session or is it when i shut down my system.
NOTE : [I][This question was asked by Leomachy][/I]
Re: Deallocating dynamically allocated heap
i think you get solution by follow the following steps:
-->write some C, c++ any code which will alocate some memory.
-->note down the address where you are allocating the memory.
-->Now meanwhile write and open another C program, which will display the
content of memory that you are allocating previously.
-->for the first program ,,,end the session and check in the second C program.
-->
Re: Deallocating dynamically allocated heap
i think you get solution by follow the following steps:
-->write some C, c++ any code which will alocate some memory.
-->note down the address where you are allocating the memory.
-->Now meanwhile write and open another C program, which will display the
content of memory that you are allocating previously.
-->for the first program ,,,end the session and check in the second C
program.
--> same way quit from the application and check in the second C program
memory content.
....................
-->
Re: Deallocating dynamically allocated heap
[QUOTE=JobHelper;5300]When i am dynamically allocating memory (heap) in a program, and in this case if i am not making an explicit deallocation call or free() call then when will this dynamicaaly allocated heap will get deallocated.Is it at the end of program or is it at the end of c session or is it when i shut down my system.
NOTE : [I][This question was asked by Leomachy][/I][/QUOTE]
When a malloc() is called some physical memory is mapped on to your process address space. When your process will ends up this memory will return to the system.
Re: Deallocating dynamically allocated heap
The allocated memory will last till you process ends. But this is not a good practice, u shuld deallocate the memory what u allocate else it can cause memory leak and your system will crash