{"id":19491016,"url":"https://github.com/quark-zju/gcmodule","last_synced_at":"2025-04-25T19:32:14.375Z","repository":{"id":38386331,"uuid":"244267044","full_name":"quark-zju/gcmodule","owner":"quark-zju","description":"Garbage collection for Rust inspired by CPython's gcmodule","archived":false,"fork":false,"pushed_at":"2022-06-05T10:40:14.000Z","size":151,"stargazers_count":21,"open_issues_count":8,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T02:41:26.912Z","etag":null,"topics":["garbage-collection","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/quark-zju.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-02T02:58:41.000Z","updated_at":"2025-04-03T15:35:04.000Z","dependencies_parsed_at":"2022-08-18T23:00:42.716Z","dependency_job_id":null,"html_url":"https://github.com/quark-zju/gcmodule","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quark-zju%2Fgcmodule","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quark-zju%2Fgcmodule/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quark-zju%2Fgcmodule/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quark-zju%2Fgcmodule/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quark-zju","download_url":"https://codeload.github.com/quark-zju/gcmodule/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250882637,"owners_count":21502341,"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":["garbage-collection","rust"],"created_at":"2024-11-10T21:15:18.828Z","updated_at":"2025-04-25T19:32:14.097Z","avatar_url":"https://github.com/quark-zju.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gcmodule\n\n[![Documentation](https://docs.rs/gcmodule/badge.svg)](https://docs.rs/gcmodule)\n[![crates.io](http://meritbadge.herokuapp.com/gcmodule)](https://crates.io/crates/gcmodule)\n![Build Status](https://github.com/quark-zju/gcmodule/workflows/build/badge.svg)\n\nGarbage collection inspired by [CPython](https://github.com/python/cpython/)'s implementation.\n\nThis library provides a type `Cc\u003cT\u003e`. It provides shared reference-counting pointer, similar to stdlib `Rc\u003cT\u003e`. Unlike `Rc`, reference cycles in `Cc` can be collected.\n\nIf all values can be freed by just reference-counting, the collector used by this library does not take extra memory. This is different from some other implementations, which require manual collection to free the extra memory used by the collector.\n\n## Example\n\n```rust\nuse gcmodule::{Cc, Trace};\nuse std::cell::RefCell;\n\ntype List = Cc\u003cRefCell\u003cVec\u003cBox\u003cdyn Trace\u003e\u003e\u003e\u003e;\nlet a: List = Default::default();\nlet b: List = Default::default();\na.borrow_mut().push(Box::new(b.clone()));\nb.borrow_mut().push(Box::new(a.clone())); // Form a cycle.\ndrop(a);\ndrop(b); // Internal values are not dropped due to the cycle.\ngcmodule::collect_thread_cycles(); // Internal values are dropped.\n```\n\nFor customized structures, they need to implement the `Trace` interface. That can be done by `#[derive(Trace)]`.\n\n```rust\nuse gcmodule::{Cc, Trace};\nuse std::cell::RefCell;\n\n#[derive(Trace, Default)]\nstruct List(RefCell\u003cVec\u003cBox\u003cdyn Trace\u003e\u003e\u003e);\n{\n    let a: List = Default::default();\n    let b: List = Default::default();\n    a.borrow_mut().push(Box::new(b.clone()));\n    b.borrow_mut().push(Box::new(a.clone()));\n}\nassert_eq!(gcmodule::collect_thread_cycles(), 2); // 2 values are collected.\n```\n\nRefer to [the documentation](https://docs.rs/gcmodule/) for more examples and technical details.\n\n## Similar Projects\n\n### [bacon-rajan-cc](https://github.com/fitzgen/bacon-rajan-cc) v0.3\n\n- Both are reference counted, with cyclic garbage collection.\n- Both are mainly single-threaded, and stop-the-world.\n- Main APIs like `Cc\u003cT\u003e` and `Trace` are similar, or even compatible.\n- `gcmodule` is conceptually simpler. There is no need for the \"colors\" concept.\n- `gcmodule` provides `ThreadedCc\u003cT\u003e` for multi-thread environment.\n- `bacon-rajan-cc` requires manual collection to release GC metadata (but not the tracked object) even if the reference count logically drops to 0. See [this commit message](https://github.com/quark-zju/gcmodule/commit/b825bc45ac008e26ada3c13daa3efa34334f8273) for some details.\n\n### [rcgc](https://github.com/jonas-schievink/rcgc) v0.1\n\n- `rcgc` takes a novel approach - the collector holds strong references while everywhere else uses weak references.\n- Therefore, `rcgc` requires manual collection to release actual objects even if the reference count of objects (logically) drops to 0.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquark-zju%2Fgcmodule","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquark-zju%2Fgcmodule","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquark-zju%2Fgcmodule/lists"}