{"id":31706644,"url":"https://github.com/veeso/leaktracer","last_synced_at":"2025-10-08T23:17:33.455Z","repository":{"id":300989813,"uuid":"1007810568","full_name":"veeso/leaktracer","owner":"veeso","description":"A Rust allocator to trace memory allocations in Rust programs, by intercepting the allocations.","archived":false,"fork":false,"pushed_at":"2025-07-07T16:44:34.000Z","size":39,"stargazers_count":38,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-18T04:52:42.528Z","etag":null,"topics":["allocator","memory-leak","memory-tracer","rust","rust-lang"],"latest_commit_sha":null,"homepage":"https://docs.rs/leaktracer","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/veeso.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null},"funding":{"github":"veeso","ko_fi":"veeso"}},"created_at":"2025-06-24T15:04:49.000Z","updated_at":"2025-09-05T07:20:40.000Z","dependencies_parsed_at":"2025-06-24T16:34:44.513Z","dependency_job_id":null,"html_url":"https://github.com/veeso/leaktracer","commit_stats":null,"previous_names":["veeso/leaktracer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/veeso/leaktracer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veeso%2Fleaktracer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veeso%2Fleaktracer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veeso%2Fleaktracer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veeso%2Fleaktracer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/veeso","download_url":"https://codeload.github.com/veeso/leaktracer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veeso%2Fleaktracer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000723,"owners_count":26082862,"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","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["allocator","memory-leak","memory-tracer","rust","rust-lang"],"created_at":"2025-10-08T23:17:24.613Z","updated_at":"2025-10-08T23:17:33.446Z","avatar_url":"https://github.com/veeso.png","language":"Rust","funding_links":["https://github.com/sponsors/veeso","https://ko-fi.com/veeso","https://www.paypal.me/chrisintin"],"categories":[],"sub_categories":[],"readme":"# leaktracer\n\n[![license-mit](https://img.shields.io/crates/l/leaktracer.svg)](https://opensource.org/licenses/MIT)\n[![repo-stars](https://img.shields.io/github/stars/veeso/leaktracer?style=flat)](https://github.com/veeso/leaktracer/stargazers)\n[![downloads](https://img.shields.io/crates/d/leaktracer.svg)](https://crates.io/crates/leaktracer)\n[![latest-version](https://img.shields.io/crates/v/leaktracer.svg)](https://crates.io/crates/leaktracer)\n[![ko-fi](https://img.shields.io/badge/donate-ko--fi-red)](https://ko-fi.com/veeso)\n[![conventional-commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits\u0026logoColor=white)](https://conventionalcommits.org)\n\n[![lib-ci](https://github.com/veeso/leaktracer/actions/workflows/cargo.yml/badge.svg)](https://github.com/veeso/leaktracer/actions)\n[![coveralls](https://coveralls.io/repos/github/veeso/leaktracer/badge.svg)](https://coveralls.io/github/veeso/leaktracer)\n[![docs](https://docs.rs/leaktracer/badge.svg)](https://docs.rs/leaktracer)\n\n---\n\n- [leaktracer](#leaktracer)\n  - [Introduction](#introduction)\n    - [Why do I need this?](#why-do-i-need-this)\n  - [Usage](#usage)\n    - [Cargo.toml](#cargotoml)\n    - [Setup](#setup)\n    - [Accessing the stats](#accessing-the-stats)\n  - [Example](#example)\n  - [Debug only](#debug-only)\n  - [Support the developer](#support-the-developer)\n  - [Changelog](#changelog)\n  - [License](#license)\n\n---\n\n## Introduction\n\nA Rust allocator to trace memory allocations in Rust programs, by intercepting the allocations.\n\nThe library provides the `LeaktracerAllocator`, which is an allocator that for each allocation, it stores the memory allocated and the allocation count for each function that allocated memory.\n\nIt's extremely easy to setup and it was designed to have something really **plug-and-play**.\n\n### Why do I need this?\n\nYou may ask why you would need this library in a language like Rust, which is known for its memory safety. The answer is that even in Rust, memory leaks can occur, especially when storing data in maps or vectors along time without cleaning them up.\n\nSometimes it can happen that you don't know where the huge memory usage is coming from, because either the cleanup method is not working, or you forgot to clean up the data. In complex applications, this can be a nightmare to debug, so that's why I created this library.\n\n## Usage\n\n### Cargo.toml\n\nAdd the following to your `Cargo.toml`:\n\n```toml\n[dependencies]\nleaktracer = \"0.1\"\n```\n\n### Setup\n\nThen, in your `main.rs` you need to **set the allocator** to `LeaktracerAllocator` and **initialize the symbol table**:\n\n```rust\nuse leaktracer::LeaktracerAllocator;\n\n#[global_allocator]\nstatic ALLOCATOR: LeaktracerAllocator = LeaktracerAllocator::init();\n```\n\nand then at the beginning of your `main` function, initialize the symbol table:\n\n```rust\nleaktracer::init_symbol_table(\u0026[\"my_crate_name\"]);\n```\n\nThe `init_symbol_table` function takes a slice of strings, which are the names of the crates you want to trace. This is useful if you have multiple crates in your project and you want to trace only specific ones.\n\nWhy is this necessary? Because the library use the `backtrace` to get the current call stack, but unfortunately the backtrace, is quite *polluted* by other non-relevant calls (such as `std::alloc`, `std::vec`, etc.), so you need to specify which crates you want to trace.\n\n### Accessing the stats\n\nOf course, once initialized you want to access the stats, to see how many allocations were made, and where they were made.\n\nYou can do this by accessing the `symbol_table` like this:\n\n```rust\nleaktracer::with_symbol_table(|table| {\n    for (name, symbol) in table.iter() {\n        println!(\n            \"Symbol: {name}, Allocated: {}, Count: {}\",\n            symbol.allocated(),\n            symbol.count()\n        );\n    }\n})?;\n```\n\nYou can also access the full amount of memory allocated and the total count of allocations by using the `LeaktracerAllocator` methods:\n\n```rust\nprintln!(\n    \"Allocated {} bytes\",\n    ALLOCATOR.allocated()\n);\n```\n\n## Example\n\nYou can find an example in the `examples` folder at `examples/tracing.rs`.\n\nYou can run the example with:\n\n```bash\ncargo run --example tracing\n```\n\n## Debug only\n\nThe `LeaktracerAllocator` is meant to be used in debug mode only, as it uses the `backtrace` crate to get the call stack, which is not available in release mode and it's extremely slow and expensive. Therefore, it is not possible to use it in release mode.\n\n## Support the developer\n\nIf you like **leaktracer**, please consider a little donation 🥳\n\n[![ko-fi](https://img.shields.io/badge/Ko--fi-F16061?style=for-the-badge\u0026logo=ko-fi\u0026logoColor=white)](https://ko-fi.com/veeso)\n[![PayPal](https://img.shields.io/badge/PayPal-00457C?style=for-the-badge\u0026logo=paypal\u0026logoColor=white)](https://www.paypal.me/chrisintin)\n\n---\n\n## Changelog\n\n[View Changelog here](CHANGELOG.md)\n\n---\n\n## License\n\nLicensed under MIT license ([SEE LICENSE](LICENSE) or \u003chttp://opensource.org/licenses/MIT\u003e)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fveeso%2Fleaktracer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fveeso%2Fleaktracer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fveeso%2Fleaktracer/lists"}