{"id":15063573,"url":"https://github.com/dominicletz/weak_ref","last_synced_at":"2025-04-10T11:12:02.158Z","repository":{"id":256386528,"uuid":"855168859","full_name":"dominicletz/weak_ref","owner":"dominicletz","description":"Weak reference for Elixir / Erlang","archived":false,"fork":false,"pushed_at":"2025-03-06T08:22:59.000Z","size":16,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T10:04:15.855Z","etag":null,"topics":["elixir"],"latest_commit_sha":null,"homepage":"https://hexdocs.pm/weak_ref","language":"Elixir","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/dominicletz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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-09-10T12:34:57.000Z","updated_at":"2025-03-06T08:23:02.000Z","dependencies_parsed_at":"2024-09-29T09:01:17.534Z","dependency_job_id":"4a599273-3717-40f6-a593-c020cfefd506","html_url":"https://github.com/dominicletz/weak_ref","commit_stats":null,"previous_names":["dominicletz/weak_ref"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominicletz%2Fweak_ref","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominicletz%2Fweak_ref/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominicletz%2Fweak_ref/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominicletz%2Fweak_ref/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dominicletz","download_url":"https://codeload.github.com/dominicletz/weak_ref/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248208563,"owners_count":21065202,"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":["elixir"],"created_at":"2024-09-25T00:04:35.543Z","updated_at":"2025-04-10T11:12:02.140Z","avatar_url":"https://github.com/dominicletz.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WeakRef\n\nWeakRef allows creating of weak references that when garbage collected will fire a \"DOWN\" message to a given process.\n\n## Usage\n\n`{strong, weak} = WeakRef.new(owner_pid \\\\ self())` creates a tangled pair of a strong and a weak reference. The strong reference is a `#Resource` and once all of it's copies are garbage collect there is a message `{:DOWN, weak, :weak_ref}` sent to the `owner_pid` process to let it know that the strong references have all gone away.\n\nThis allows implementing logic to clean up external resources when there are no internal references to those available. \n\nThis is an iex shell example, so we need to take care let the ref be garbage collected and not referenced by the history of the shell (reason for the `elem` call).\n\n```elixir\npid = spawn(fn -\u003e \n  receive do \n    {:DOWN, id, :weak_ref} -\u003e\n      IO.puts(\"The weak_ref with id=#{id} was garbage collected!\")\n  end\nend)\n\nelem(WeakRef.new(pid), 1)\n```\n\n## Installation\n\nAdd `:weak_ref` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:weak_ref, \"~\u003e 1.0.0\"}\n  ]\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdominicletz%2Fweak_ref","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdominicletz%2Fweak_ref","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdominicletz%2Fweak_ref/lists"}