Manual Memory Management

You allocate and deallocate heap memory yourself.

If not done with care, this can lead to crashes, bugs, security vulnerabilities, and memory leaks.

C Example

You must call free on every pointer you allocate with malloc:

  1. void foo(size_t n) {
  2. int* int_array = (int*)malloc(n * sizeof(int));
  3. //
  4. // ... lots of code
  5. //
  6. free(int_array);
  7. }

Memory is leaked if the function returns early between malloc and free: the pointer is lost and we cannot deallocate the memory.