I have two related questions, so I ask them in this single thread.
Q1) How can I confirm that my OS automatically frees up “free” memory (allocated with malloc) automatically when the program exits? I am using Ubuntu 11.04, 32-bit with gcc-4.5.2
According to Stephen Summit's study page here , “Free unused memory (malloc'ed) is a good idea, but it is not mandatory. When your program terminates, any memory that it allocated but did not free should be automatically released. If your computer somehow "lost" memory just because your program forgot to free it, it would mean a problem or a lack of your operating system . "
Q2) Suppose foo.c modifies the memory of B-bytes. Later, foo.c frees these B-byte memory cells and returns them to the OS. Now my question is , can these DEFINED B-bytes of memory locations be redistributed to foo.c (by the operating system) in the current instance, or can these B-bytes not be allocated to foo.c until its current instance terminates?
EDIT . I would recommend to anyone who reads my question to read the answer to a similar question here and. Both answers explain the interaction and operation of malloc () and free () with good granularity without the use of very esoteric terms. To understand the DIFFERENCE between the memory management tools used by the kernel (e.g. brk (), mmap ()) and those used by the C compiler (e.g. malloc (), free ()), this is MUST BE READ.
source
share