From what I understand because malloc dynamically assigns mem , you need to free that mem so that it can be used again.
Let's take those one point at a time...
If you return a char *
that you know was created with malloc
, then yes, it is your responsibility to free that. You can do that with free(myCharPtr)
.
The OS will claim the memory back, and it won't be lost forever, but there's technically no guarantee that it will be reclaimed right when the application dies. That just depends on the operating system.