{"id":27039991,"url":"https://github.com/rimkomatic/garbagecollector","last_synced_at":"2025-10-06T18:18:47.782Z","repository":{"id":242979054,"uuid":"811119789","full_name":"Rimkomatic/GarbageCollector","owner":"Rimkomatic","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-23T07:51:15.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-23T08:28:40.776Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Rimkomatic.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-06T01:17:39.000Z","updated_at":"2025-03-23T07:51:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"30d301d7-79bd-43e7-acef-1b50c61fb9fd","html_url":"https://github.com/Rimkomatic/GarbageCollector","commit_stats":null,"previous_names":["rimkomatic/garbagecollector"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rimkomatic%2FGarbageCollector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rimkomatic%2FGarbageCollector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rimkomatic%2FGarbageCollector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rimkomatic%2FGarbageCollector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Rimkomatic","download_url":"https://codeload.github.com/Rimkomatic/GarbageCollector/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247284933,"owners_count":20913690,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-05T03:27:30.381Z","updated_at":"2025-10-06T18:18:42.756Z","avatar_url":"https://github.com/Rimkomatic.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Garbage Collector in C\n\nThis project is an implementation of a simple garbage collector in C.\n\n## Overview\n\nGarbage collection is a form of automatic memory management that aims to reclaim memory occupied by objects that are no longer in use by the program. This project demonstrates a basic garbage collection system using the mark-and-sweep algorithm.\n\n## Key Components\n\n### 1. Memory Management\nThe garbage collector manages a pool of memory blocks. These blocks are dynamically allocated as needed and freed when they are no longer reachable.\n\n### 2. Mark-and-Sweep Algorithm\nThe algorithm operates in two phases:\n- **Mark Phase**: Traverse the graph of references starting from the root and mark all reachable objects.\n- **Sweep Phase**: Scan through all objects and free those that are not marked.\n\n### 3. Object Representation\nEach object managed by the garbage collector contains metadata including:\n- A mark bit indicating whether the object is reachable.\n- A size field specifying the size of the object.\n- A pointer to the next object in the list.\n\n## Implementation Details\n\n### Memory Pool\nThe memory pool is a contiguous block of memory from which objects are allocated. The pool is initialized once and objects are allocated from it until it is exhausted.\n\n### Allocation\nObjects are allocated from the memory pool using a simple bump-pointer allocator. If the pool is exhausted, the garbage collector is invoked to free up memory.\n\n### Collection\nThe collection process involves:\n1. **Marking**: Start from the roots (global variables, stack variables) and recursively mark all reachable objects.\n2. **Sweeping**: Traverse the memory pool and free all unmarked objects, adding their memory back to the pool.\n\n## Example Usage\n\n```c\n#include \"gc.h\"\n\nint main() {\n    gc_init(); // Initialize the garbage collector\n\n    // Allocate some objects\n    Object *obj1 = gc_alloc(sizeof(Object));\n    Object *obj2 = gc_alloc(sizeof(Object));\n\n    // Set up references\n    obj1-\u003eref = obj2;\n\n    // Manually invoke garbage collection\n    gc_collect();\n\n    gc_shutdown(); // Clean up and free all allocated memory\n    return 0;\n}\n\n```\n\n## Building and Running\n\nTo build and run the project, use the following commands:\n``` bash\ngcc -o gc_example gc_example.c gc.c\n./gc_example\n```\n\n\n## License\nThis project is licensed under the MIT License.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frimkomatic%2Fgarbagecollector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frimkomatic%2Fgarbagecollector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frimkomatic%2Fgarbagecollector/lists"}