{"id":13771902,"url":"https://github.com/denis-ryzhkov/mem_top","last_synced_at":"2026-02-10T21:34:10.059Z","repository":{"id":17421448,"uuid":"20194501","full_name":"denis-ryzhkov/mem_top","owner":"denis-ryzhkov","description":"Shows top suspects for memory leaks in your Python program.","archived":false,"fork":false,"pushed_at":"2022-07-13T15:38:17.000Z","size":13,"stargazers_count":79,"open_issues_count":0,"forks_count":9,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-01T11:57:33.842Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","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/denis-ryzhkov.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":"2014-05-26T18:13:31.000Z","updated_at":"2025-03-28T01:44:12.000Z","dependencies_parsed_at":"2022-08-07T08:16:00.206Z","dependency_job_id":null,"html_url":"https://github.com/denis-ryzhkov/mem_top","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/denis-ryzhkov/mem_top","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denis-ryzhkov%2Fmem_top","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denis-ryzhkov%2Fmem_top/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denis-ryzhkov%2Fmem_top/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denis-ryzhkov%2Fmem_top/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/denis-ryzhkov","download_url":"https://codeload.github.com/denis-ryzhkov/mem_top/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denis-ryzhkov%2Fmem_top/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29317956,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-10T20:44:44.282Z","status":"ssl_error","status_checked_at":"2026-02-10T20:44:43.393Z","response_time":65,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-08-03T17:00:57.374Z","updated_at":"2026-02-10T21:34:10.038Z","avatar_url":"https://github.com/denis-ryzhkov.png","language":"Python","funding_links":[],"categories":["Memory Management"],"sub_categories":[],"readme":"# mem_top\n\nShows top suspects for memory leaks in your Python program.\n\n## Usage\n\n    pip install mem_top\n    from mem_top import mem_top\n\n    # From time to time:\n    logging.debug(mem_top())\n    # print(mem_top())\n\n    # Notice which counters keep increasing over time - they are the suspects.\n\n## Counters\n\n`mem_top` iterates all objects found in memory and calculates:\n\n* refs - number of direct references from this object to other objects, like keys and values of dict\n    * E.g. a dict `{(\"some\", \"complex\", \"key\"): \"value\"}` will have `refs: 2` - 1 ref for key, 1 ref for value\n    * Its key `(\"some\", \"complex\", \"key\")` will have `refs: 3` - 1 ref per item\n* bytes - size of this object in bytes\n* types - number of objects of this type still kept in memory after garbage collection\n\n## Real life example\n\n    refs:\n    144997  \u003ctype 'collections.defaultdict'\u003e defaultdict(\u003ctype 'collections.deque'\u003e, {\u003cGearmanJobRequest task='...', unique='.\n    144996  \u003ctype 'dict'\u003e {'.:..............:.......': \u003cGearmanJobRequest task='..................', unique='.................\n    18948   \u003ctype 'dict'\u003e {...\n    1578    \u003ctype 'dict'\u003e {...\n    968     \u003ctype 'dict'\u003e {...\n    968     \u003ctype 'dict'\u003e {...\n    968     \u003ctype 'dict'\u003e {...\n    767     \u003ctype 'list'\u003e [...\n    726     \u003ctype 'dict'\u003e {...\n    608     \u003ctype 'dict'\u003e {...\n\n    types:\n    292499  \u003ctype 'dict'\u003e\n    217912  \u003ctype 'collections.deque'\u003e\n    72702   \u003cclass 'gearman.job.GearmanJob'\u003e\n    72702   \u003cclass 'gearman.job.GearmanJobRequest'\u003e\n    12340   \u003ctype '...\n    3103    \u003ctype '...\n    1112    \u003ctype '...\n    855     \u003ctype '...\n    767     \u003ctype '...\n    532     \u003ctype '...\n\n* Noticed a leak of 6GB RAM and counting.\n* Added \"mem_top\" and let it run for a while.\n* When got the result above it became absolutely clear who is leaking here:  \nthe Python client of Gearman kept increasing its counters over time.\n* Found its known bug - https://github.com/Yelp/python-gearman/issues/10  \nleaking defaultdict of deques, and a dict of GearmanJobRequest-s,  \njust as the \"mem_top\" showed.\n* Replaced \"python-gearman\" - long story: stale 2.0.2 at PyPI, broken 2.0.X at github, etc.\n* \"mem_top\" confirmed the leak is now completely closed.\n\n## Updates\n\n* Pass e.g. `verbose_types=[dict, list]` to store their values,\n  sorted by `repr` length descending,\n  in `verbose_file_name` or returned from `mem_top()`.\n* Added \"bytes\" top.\n\n## Config defaults\n\n```\nmem_top(\n    limit=10,                           # limit of top lines per section\n    width=100,                          # width of each line in chars\n    sep='\\n',                           # char to separate lines with\n    refs_format='{num}\\t{type} {obj}',  # format of line in \"refs\" section\n    bytes_format='{num}\\t {obj}',       # format of line in \"bytes\" section\n    types_format='{num}\\t {obj}',       # format of line in \"types\" section\n    verbose_types=None,                 # list of types to sort values by `repr` length\n    verbose_file_name='/tmp/mem_top',   # name of file to store verbose values in\n)\n```\n\n## See also\n\n* https://docs.python.org/2/library/gc.html#gc.garbage\n* https://pypi.python.org/pypi/objgraph\n\n## About\n\nmem_top version 0.2.1  \nCopyright (c) 2014-2022 Denis Ryzhkov \u003cdenisr@denisr.com\u003e  \nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenis-ryzhkov%2Fmem_top","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdenis-ryzhkov%2Fmem_top","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenis-ryzhkov%2Fmem_top/lists"}