{"id":14981328,"url":"https://github.com/alexpineda/three-janitor","last_synced_at":"2025-10-29T05:31:29.811Z","repository":{"id":58295329,"uuid":"530973767","full_name":"alexpineda/three-janitor","owner":"alexpineda","description":"A janitor is a utility class that can be used to clean up resources, especially GPU allocated ones, that are no longer needed by your program.","archived":false,"fork":false,"pushed_at":"2022-09-22T01:07:48.000Z","size":68,"stargazers_count":4,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-16T21:48:43.552Z","etag":null,"topics":["three","three-js","threejs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/alexpineda.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}},"created_at":"2022-08-31T07:14:05.000Z","updated_at":"2023-06-02T11:32:01.000Z","dependencies_parsed_at":"2023-01-18T16:45:32.630Z","dependency_job_id":null,"html_url":"https://github.com/alexpineda/three-janitor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alexpineda/three-janitor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexpineda%2Fthree-janitor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexpineda%2Fthree-janitor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexpineda%2Fthree-janitor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexpineda%2Fthree-janitor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexpineda","download_url":"https://codeload.github.com/alexpineda/three-janitor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexpineda%2Fthree-janitor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281069102,"owners_count":26438554,"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-26T02:00:06.575Z","response_time":61,"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":["three","three-js","threejs"],"created_at":"2024-09-24T14:03:20.019Z","updated_at":"2025-10-29T05:31:29.542Z","avatar_url":"https://github.com/alexpineda.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# THREE Object Janitor\n\n[![Version](https://badgen.net/npm/v/three-janitor?color=green)](https://www.npmjs.com/package/three-janitor)\n\n\u003e A janitor is a utility class that can be used to clean up resources, especially GPU allocated ones, that are no longer needed by your program.\n\n## Installation\n\nThe library only requires the peer dependency [three](https://github.com/mrdoob/three.js/).\n\n```sh\nnpm install three three-janitor\n```\n\n## Usage\n\n```ts\nimport { Janitor } from \"three-janitor\"\n\nconst janitor = new Janitor();\n\n// Object3D\nconst myObject = new THREE.Mesh(...);\njanitor.mop(myObject);\n\n// add callbacks with optional label\nconst music = new Beethoven();\nmusic.play();\njanitor.mop(() =\u003e music.stop(), \"music\")\n\n// add another janitor to the top level janitor\n// this works sinsce Janitor is a `Disposable` type anyway\njanitor.mop(someNestedFunctionThatReturnsAJanitor());\n\n// html elements are tracked and then removed from their parents when dispose() is called\nconst myElement = document.createElement(\"div\");\njanitor.mop(myElement);\n\n// when you're done with it, clean it all up.\njanitor.dispose();\n\n```\n\n### When calling `Janitor.dispose()`\nIt will go through all the following:\n\n- For `Object3DLike`\n   - disposes any `geometry`\n   - disposes any and all `material` or `material[]`\n   - visits each `material` and disposes any `Texture` property\n   - visits each `uniform` and disposes any `Texture` value\n   - visits `children` and repeats the process.\n   - supports Object3DLike objects like `Point`\n   - works great for entire `Scene` objects.\n- For callbacks it will simply call them.\n- For `Disposable` objects it will call `dispose()`\n- For HTMLElement objects it will call `remove()`\n- It will accept iterable types containing any of the above.\n\n\n## Utilities\n\n```ts\n// labels for debug logging dispose() calls\nconst janitor = new Janitor(\"My Module\"); \nJanitor.logLevel = JanitorLogLevel.Info;\n```\n\n```ts\n// single line method, returns the argument\nconst myOtherObject = janitor.mop(new THREE.Mesh(...));\n```\n\n\n```ts\n// call dispose directly without mop()\njanitor.dispose(myObj, myObj2); \n```\n\n```ts\n// same thing statically\nJanitor.trash(myObj); \n```\n\n```ts\n// add event listeners and don't worry about cleaning up\njanitor.addEventListener(window, \"click\", () =\u003e alert(`I'm good to go`));\n```\n\n```ts\n// same thing for using node like event emitters\njanitor.on(ipcRenderer, \"message\", () =\u003e ...);\n```\n\n```ts\n// aliases for your preference\njanitor.add();\njanitor.track();\njanitor.mop();\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexpineda%2Fthree-janitor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexpineda%2Fthree-janitor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexpineda%2Fthree-janitor/lists"}