Is there any way to clean unused packages in go mod directory? currently when you use go mod to manage you dependencies,new packages are added and old ones are not removed.
So can we maintain a global gomod.stats file to keep reference counter of every package? It can only be modified when executing `go mod download/init/tidy` and when running `go mod clean`, it will traverse gomod.stats and find packages who's refcount is 0 then delete them. This is similar to simplified GC using reference counting and I think customizing digraph may deal with it. https://en.wikipedia.org/wiki/Directed_graph https://en.wikipedia.org/wiki/Reference_counting#Graph_interpretation this is golang.org/x/tools packages in my GOPATH/pkg/mod, totally 32 directories with 41463 files and 16185 sub-directories. It's not necessary now but I think wo need it sooner or later. ``` D:\~\go\pkg\mod\golang.org\x>dir | findstr tools 2020/07/02 周四 19:36 <DIR> tools 2020/01/09 周四 23:02 <DIR> tools@v0.0.0-20180824175216-6c1c5e93cdc1 2020/01/09 周四 23:03 <DIR> tools@v0.0.0-20181130195746-895048a75ecf 2019/11/12 周二 15:00 <DIR> tools@v0.0.0-20190312170243-e65039ee4138 2020/01/09 周四 23:02 <DIR> tools@v0.0.0-20190408220357-e5b8258f4918 2020/04/24 周五 14:47 <DIR> tools@v0.0.0-20190611222205-d73e1c7e250b 2019/11/20 周三 15:46 <DIR> tools@v0.0.0-20190809145639-6d4652c779c4 2019/12/13 周五 17:16 <DIR> tools@v0.0.0-20191012152004-8de300cfc20a 2020/01/09 周四 23:03 <DIR> tools@v0.0.0-20191030062658-86caa796c7ab 2019/11/19 周二 14:59 <DIR> tools@v0.0.0-20191108194844-46f05828f2fe 2019/11/19 周二 14:59 <DIR> tools@v0.0.0-20191118222007-07fc4c7f2b98 2020/01/09 周四 23:03 <DIR> tools@v0.0.0-20191125144606-a911d9008d1f 2019/12/11 周三 16:41 <DIR> tools@v0.0.0-20191206201009-952e2c076240 2019/12/11 周三 16:41 <DIR> tools@v0.0.0-20191210221141-98df12377212 2020/01/09 周四 23:02 <DIR> tools@v0.0.0-20200108203644-89082a384178 2020/02/28 周五 10:24 <DIR> tools@v0.0.0-20200130002326-2f3ba24bd6e7 2020/02/18 周二 16:59 <DIR> tools@v0.0.0-20200212213342-7a21e308cf6c 2020/02/18 周二 16:59 <DIR> tools@v0.0.0-20200216192241-b320d3a0f5a2 2020/04/30 周四 15:41 <DIR> tools@v0.0.0-20200226224502-204d844ad48d 2020/03/03 周二 12:29 <DIR> tools@v0.0.0-20200227200655-6862ededa516 2020/02/28 周五 10:23 <DIR> tools@v0.0.0-20200227222343-706bc42d1f0d 2020/03/03 周二 12:29 <DIR> tools@v0.0.0-20200302225559-9b52d559c609 2020/06/15 周一 22:39 <DIR> tools@v0.0.0-20200304193943-95d2e580d8eb 2020/03/25 周三 16:50 <DIR> tools@v0.0.0-20200316194252-fafb6e2e8a4a 2020/03/25 周三 16:50 <DIR> tools@v0.0.0-20200325010219-a49f79bcc224 2020/04/10 周五 17:48 <DIR> tools@v0.0.0-20200407041343-bf15fae40dea 2020/04/10 周五 17:48 <DIR> tools@v0.0.0-20200410040751-3bd20875a2eb 2020/04/30 周四 15:40 <DIR> tools@v0.0.0-20200430040329-4b814e061378 2020/05/11 周一 21:46 <DIR> tools@v0.0.0-20200509030707-2212a7e161a5 2020/05/15 周五 09:43 <DIR> tools@v0.0.0-20200513154647-78b527d18275 2020/05/15 周五 09:43 <DIR> tools@v0.0.0-20200515010526-7d3b6ebf133d 2020/07/02 周四 19:36 <DIR> tools@v0.0.0-20200701133321-6ddc6be4d35f 2020/07/02 周四 19:36 <DIR> tools@v0.0.0-20200702044944-0cc1aa72b347 ``` Thanks. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/1f46b3cc-6434-4589-822e-a38464bc1387n%40googlegroups.com.