79658328

Date: 2025-06-09 03:38:46
Score: 1
Natty:
Report link

When a process (including a daemon) exits, the OS reclaims all its allocated memory, including

  1. Heap memory allocated with malloc
  2. Stack memory
  3. File descriptors
  4. Memory mappings
  5. Other resources (with exceptions like shared memory)

Answer

Yes, the OS will automatically reclaim all memory when the daemon process exits.

However,

This applies only on process termination.If your daemon is long-running and keeps allocating memory without freeing it, this can lead to memory leaks and exhaustion over time.

If your process is short-lived (utility that runs and exits), skipping free() is generally acceptable.

Tools like Valgrind will report such allocations as "still reachable" or "not freed", even though the OS reclaims them, because they were never explicitly freed.

For some resources (temporary files, shared memory, or mutexes), relying on process exit alone may not be sufficient.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Starts with a question (0.5): When a
  • Low reputation (0.5):
Posted by: Vinuka Osura