Debugging Dynamically Allocated Memory
As you may know, dynamically allocated memory (DAM) is memory that a program requests from the heap with functions like malloc()
and
calloc()
.[25] Dynamically allocated memory is typically used for data structures like binary trees and linked lists, and it is also at work behind the scenes when you create an object in object-oriented programming. Even the standard C library uses DAM for its own internal purposes. You may also recall that dynamic memory must be freed when you're done with it.[26]
DAM problems are notoriously difficult to find and fall into a few general categories:
-
Dynamically allocated memory is not freed.
-
The call to
malloc()
fails (this is easy to detect by checking the return ...
Get The Art of Debugging with GDB, DDD, and Eclipse now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.