title: why C doesn't have built-in conservative garbage collection in malloc
body: <p>We know that memory leak is one of the most common/serious problems when writting C programs. I know it is the responsibility of programmers to free memory by calling <code>free()</code>, but it is still feasible to integrating a conservative garbage collector into malloc package.</p>
  <p><a href="https://i.stack.imgur.com/k9Gz8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k9Gz8.png" alt="enter image description here" /></a></p>
  <p>Of course this garbage collector is <strong>conservative</strong> since C does not tag memory locations with type information (unlike Java's full-fledged garbage collector), there is no way for the collector in C to infer that the data is really an int e.g and not a pointer. Therefore, the allocator must conservatively mark a block as reachable, when in fact it might not be. But it is OK, it will still function correclty just not being able to free all unreachable blocks, it is better than nothing.</p>
  <p>So why C doesn't have built-in conservative garbage collection in <code>malloc</code> to relieve programmers' burden?</p>