{"id":31952911,"url":"https://github.com/shevakuilin/nsdeallocnotifier","last_synced_at":"2025-10-14T13:25:48.130Z","repository":{"id":246011632,"uuid":"193472028","full_name":"shevakuilin/NSDeallocNotifier","owner":"shevakuilin","description":"一个 NSMapTable strong-weak释放的可行性验证方案","archived":false,"fork":false,"pushed_at":"2019-06-24T10:24:54.000Z","size":40,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-25T11:05:54.770Z","etag":null,"topics":["autorelease","dealloc","deinit","nsmaptable"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/shevakuilin.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-24T09:09:16.000Z","updated_at":"2024-06-25T11:06:01.298Z","dependencies_parsed_at":"2024-06-25T11:05:59.581Z","dependency_job_id":null,"html_url":"https://github.com/shevakuilin/NSDeallocNotifier","commit_stats":null,"previous_names":["shevakuilin/nsdeallocnotifier"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/shevakuilin/NSDeallocNotifier","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shevakuilin%2FNSDeallocNotifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shevakuilin%2FNSDeallocNotifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shevakuilin%2FNSDeallocNotifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shevakuilin%2FNSDeallocNotifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shevakuilin","download_url":"https://codeload.github.com/shevakuilin/NSDeallocNotifier/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shevakuilin%2FNSDeallocNotifier/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279018708,"owners_count":26086606,"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-14T02:00:06.444Z","response_time":60,"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":["autorelease","dealloc","deinit","nsmaptable"],"created_at":"2025-10-14T13:25:05.594Z","updated_at":"2025-10-14T13:25:48.125Z","avatar_url":"https://github.com/shevakuilin.png","language":"Swift","readme":"#### 一个 NSMapTable strong-weak释放的可行性验证方案\n\nNSMapTable 的 weak 自动释放并不像 Apple 描述的那么可靠([弱引用归零存在问题](http://cocoamine.net/blog/2013/12/13/nsmaptable-and-zeroing-weak-references/)，并不符合官方描述的预期，无论是weak-strong还是strong-weak亦或是其他类型)，所以参考了一些思路，实现了一个可以令其稳定释放的方案\n\n\u003cb\u003e核心思路：\u003c/b\u003e\n- 创建一个自定义类 NSDeallocNotifier，该类在实例化构造时接收一个 block 作为参数，并在该类析构 (deinit/dealloc) 时执行该 block.\n- 在需要 NSMapTable 添加对象时，实例化一个 NSDeallocNotifier，并在其回调块中执行 NSMapTable 的 remove 方法来删除其中的键/值对，也就是说在 NSDeallocNotifier 释放时，同时释放掉 NSMapTable 中的键/值对.\n- 将实例化的 NSDeallocNotifier 以关联对象的方式，添加到键/值对上。保证当 weak 持有的键/值对象被 deinit/dealloc 时，所关联的 NSDeallocNotifier 也将被 deinit/dealloc，从而会触发 block，也就会跟着及时释放 NSMapTable 中的键/值对。\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshevakuilin%2Fnsdeallocnotifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshevakuilin%2Fnsdeallocnotifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshevakuilin%2Fnsdeallocnotifier/lists"}