
Design and implement a memory leak detector tool for C and C++ programs, tackling memory management, leakage, and corruption in a project-based course.
Join the Telegram group for the system c project on writing a garbage collector from scratch.
Install Linux or Unix, set up GCC, and refresh C programming with pointers and memory management for the System C project; access the code on GitHub via git.
Build a memory leak detector library for C or C++ that tracks heap objects and references to identify leaks, and use GitHub to manage code and showcase your project.
Explore the high-level architecture of a memory management system with a three-component design - C application, library, and kernel - and how the library intermediates allocation requests and tracks memory.
The project unfolds in three phases: a structured database for structures, an object database for application objects, and a memory leak detection algorithm that uses both databases to locate leaks.
Design and implement phase one by registering all structures used by the application, building a link list based structured database that the library maintains, using structure names as keys.
During initialization, the C application conveys structure details—field count, names, data types, and sizes—to the library, which stores them in its internal structured database.
Model a library's structured database as a linked list of structure database records, enforcing 128-character limits for names, with each record detailing key size, field count, and field info.
Learn how to register a C structure with the library by building a structured database record, a field array, and pointer-aware fields using the employee example.
Walk through registering an employee structure with the library, print and verify the structured database records, and set up the library in C with .c and .h files.
Demonstrates phase one of the project by implementing print structure record, print structure database, and add structure to structured database, compiling and running to verify employee and student structure registrations.
Phase one completes structure registration with library, gathering information about structures and their layout for the structure database to manipulate application objects, while phase two begins with object database creation.
Phase two designs and implements the library's object database. Each logged object creates an object record with its structure details and address, enabling the library to track dynamic objects.
Explains modeling an object database for a library as a linked list of object records, with next pointers, object pointers, and unit counts, plus x log and x clock memory management.
The lecture demonstrates dynamic object creation with x calloc, showing how the object database populates and links to the structured database records, while x log registers student and employee objects.
Walk through the design and implementation of an object database for a garbage collector, including object and record structures, adding objects, dump functions, and memory leak detection setup.
Register application structures with the library at initialization. Use a structured read-only database and an object database to track dynamic objects and detect memory leaks in phase three.
Implement a memory leak detection algorithm in the library to process object and structured databases and identify leaked objects not reachable from root objects, and report them to the developer.
Explore memory leak detection algorithm within a graph-based view of application data structures. Model objects as nodes and references as edges in disjoint graphs, identifying leaked objects not reachable.
Identify reachable and leaked objects by tracing from root objects via global variables, recognizing disjoint graphs of application data structures. Understand that leaked objects lie outside reachable graphs.
Explore how an application's data structures evolve from disjoint graphs into directed acyclic graphs as objects reference one another, illustrating memory leak detection with library and university management examples.
Register global objects as root or set dynamic objects as root to enable the library to start memory leak detection from these roots.
Learn route object management in the Amaldi library, introducing an is_route flag for root objects and two APIs to register a global root and set a root by key.
Practice memory leak detection by applying the MLD algorithm to a directed acyclic object graph, using root objects, is_root and is_visited flags, and parent and child relationships to identify leaks.
Explore the dry run of a memory leak detection algorithm (mld) on an object graph, using root objects, checkpoints, and depth-first search to identify leaked objects.
Demonstrate the level 1 pseudocode for a memory leak detection algorithm, initializing the object database, locating root objects, marking them unvisited, and recursively exploring reachable objects.
Implement recursive exploration of objects from a parent object, marking visited children, calculating child addresses via field offsets, and handling arrays of root objects like a depth-first search.
Enhance the garbage collector to detect memory leaks from primitive objects by registering primitive data types in the library's structured database, enabling x calloc use and native leak detection.
Watch a complete demo of our memory leak detection library as it registers structures, builds an object and structure database, marks root objects, and reports leaked objects.
analyze the project so far, examine the reachability-based garbage collection approach, and discuss how tricky C/C++ tricks can cause false leaks that Java would not.
Explain how storing a designation's address in an unsigned int can fool a garbage collector in C/C++. Show that Java prohibits this binding, avoiding false alarms.
Show how interior pointers between employee and designation objects prevent memory-leak detection, using a linked-list node and the rule that memory must point to the starting address.
Explore case three where embedded objects in C/C++ trigger library failure, contrasted with Java's lack of embedded objects; learn how embedded structures and references affect garbage collection.
Analyze why unions pose a challenge for a Java library, demonstrate union size as the largest member, and illustrate with doctor and engineer structures.
Emphasize that pure object oriented C/C++ limits the library benefits, while direct memory access and pointers reveal the strengths of C/C++ beyond Java-like garbage collection.
Learn how makefiles simplify building large software on unix-like systems, handling compilation, linking, libraries, and installation while managing dependencies for complex projects.
Understand how a dependency tree underpins Makefile, where a final target depends on subcomponents, with the root representing the delicious meal and changes propagating bottom-up to ancestors.
Learn to write a makefile that builds an executable from main.c and a static library from common_math.c, complex_math.c, and trig_math.c, via object files.
Learn to build with make by writing rules that convert sources to object files and libraries. Use gcc commands with -I header paths and libm linking to produce an executable.
Discover how a makefile coordinates building a final executable by using rules, dependencies, depth-first postorder traversal, compiling main.o, building a static library, and a clean rule.
Discover coding projects that strengthen your resume across operating system networking, Linux system programming, and multithreading. Learn debugging techniques on Linux socket programming and apply thread synchronization to real projects.
I was asked this question in Amazon/Google Interviews :
1. How would you design a garbage collector for C programs?
2. If designing a garbage collector was that easy, why we don’t have it integrate with C programming language already ??
Complete this course to get the answers. :p
This course is a Project-based course and involved coding in C at every stage of the course.
Mention this project on your Resume with all proud.
This is a C Project (open for extension for C++) in which you will learn and write a library that catches the memory leaks, if any, by the application. In this project, I have explained step by step how to design and implement a garbage collector library called MLD (Memory Leak Detector) which when integrated to your application will provide the facility to catch leaked objects and report them. MLD library will be the generic library and has the ability to parse any application's data structures and manipulate them.
The Project is explained in 3 phases.
Note: This is a course that require a little bit of analysis power, beginner students can also learn much from this course that how you can create a program which can parse its own objects and structures. This technique is used to create many other projects out of which one is Memory leak detection.
Advice: Class of Students who needs "spoon-feeding", pls refrain from enrolling in project-based courses.
Key highlights :
Since the advent of C/C++ Programming language, Memory management is one of the responsibilities which the developer has to deal with
C/C++ Softwares often suffers from Two Memory related Problems :
Memory corruption
Memory leak
Unlike Java, C/C++ does not have the luxury for automatic garbage collection
Java does not allow programmer to access the physical memory directly, but C/C++ does, not does java expose pointers directly to the developer/coder. Therefore Java applications do not suffer from Memory corruption either, but C/C++ does
In this course, we will design and implement Memory Leak Detector (MLD) tool for C programs, easily extensible to C++ as well
Some Students have requested to provide a formal description of this project. For Students who want to mention this project in their resume, or doing this project as their OS project - you can mention the following title and abstract of this project as below :
Title: "Design and Implementation of Java-like Garbage Collector for C Programs".
In this project, we try to implement a garbage collector for C programs which work on the principle of reachability of objects to detect memory leaks. Through this project, we understand the limitation of such a garbage collector for C like programming languages (which have direct access to underlying memory addresses, unlike Java/python) and analyze its limitations and cost for being an inbuilt feature of C-like language.