Although I say return memory to the operating system, that isn't necessarily what happens. malloc() and free() are library calls that offer some abstraction on top of syscalls.
malloc() and free() interact with the memory allocator/heap, which may in turn interact with the system. The underlying syscalls are somewhat expensive, and the memory allocator will try to avoid making these calls unless necessary — therefore, if you free() a small chunk of memory, it's possible it's returned to the heap so that if you may decide to use memory again soon, it's easily accessible.
What happens exactly will depend on the compiler, the operating system, how much memory is being requested, etc.
👨💻 Learn Test-Driven Development with Laravel!
https://tddwithlaravel.com
Sign up to 30 Days of Laravel 👉🏻 https://30daysoflaravel.com
👨💻 Sign up to my newsletter and receive PHP, JS and Laravel news in a weekly-basis:
https://subscribe.mateusguimaraes.com
🎉 Party up:
/ mateusjatenee
/ mateusjatenee
/ mateusguimaraes
Thanks for watching!