0

I am declaring variables( Pointer ) and dynamically allocating memory to them in one function (malloc) and then using those variables in other function as well and then using free() in other function itself to free them after their use is over.

My doubt is : Are memory sections pointed by those pointers actually getting freed? And How to know while debugging if memory sections are freed after we execute free()?

  • Mostly, no. Reason: Performance. – Sourav Ghosh Jun 22 '15 at 10:38
  • 1
    The sections are free after call to `free()`. They are free to the program to be reused but usually not returned to the operation system (if any). In embdded environment you find the memory actrually free. So the answer is: *it depends*. The pointers are not changed by `free()` so they have the same value. Since they point to memory that is not allocated anymore you must not derefence them. – harper Jun 22 '15 at 10:43
  • I am using Code Composer Studio 5.3 software and the code is run on multi-core processor TMS320C6678. Can you clarify whether its possible to free the memory as in the case given? – Sheetal Jun 22 '15 at 10:50

0 Answers0