Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: types are not garbage collected #28783

rogpeppe opened this issue Nov 13, 2018 · 2 comments


Copy link

@rogpeppe rogpeppe commented Nov 13, 2018

go version devel +644ddaa842 Wed Nov 7 16:12:02 2018 +0000 linux/amd64

Newly created types are not garbage collected, so code which creates types on the fly in response to runtime data can leak memory.

This code prints a large number when it should print zero:


This comment has been minimized.

Copy link

@randall77 randall77 commented Nov 13, 2018

Yep. This is a hard one to fix.
We depend on type uniqueness, so we need to keep track of all the types we've currently made.
To GC the type, we need some way of telling reflect we've done so, so it can remove that type from its list of created types. Probably something akin to Java's weak references.
All the interface tables are allocated in persistent memory, not on the heap, so that would need to change also.
The compiler has a bunch of assumptions about types and interface tables never being GCd (e.g. the first word of an interface isn't a pointer that GC needs to traverse), that would need finding and fixing also.

Somewhat related to #20461


This comment has been minimized.

Copy link

@bradfitz bradfitz commented Nov 13, 2018

Could you split the the runtime type into two parts: a persistent-alloc single word indirection pointer to the second GC-able part with all the fields? But that's only a constant factor improvement and just delays the problem, probably.

@bcmills bcmills added the Performance label Nov 19, 2018
@bcmills bcmills added this to the Unplanned milestone Nov 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
4 participants
You can’t perform that action at this time.