Interview Question

What is memory leak?

Prevent leaks by pairing successful allocations with clear ownership and cleanup.

💡 Concept ✅ Quick Revision ⚙ C

Answer

A memory leak occurs when allocated storage remains allocated but the program can no longer release or use it as intended. • C does not provide automatic garbage collection for malloc allocations. • Every successful allocation needs a clear ownership and release path. • Long-running leaks can increase resource use until allocation fails.

💡 C Example

int *value = malloc(sizeof *value); if (value != NULL) { *value = 10; free(value); }

⚡ Quick Revision

Prevent leaks by pairing successful allocations with clear ownership and cleanup.