-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
Comments
Yep. This is a hard one to fix. Somewhat related to #20461 |
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. |
I've just found out that the API framework I've developed leaks memory as I make heavy use of reflect.StructOf. Perhaps there should be a note on the reflect package about types not being garbage collected ? |
I also believe this just needs to be documented better and needs no fix. The reflect package is an expert interface and as such the user of it needs to take pre-cautions and not the Go team. Type identity by pointer and off-heap type information seem to be more valuable to me at least than making weird usages of an expert level API more convenient and safe. |
That sounds like a cop-out to me, I'm afraid. I'm not convinced that allowing types to be GC'd necessarily implies that either of those two things cannot be done. While this might seem like a minor issue for now, if we ever fix Go's plugin system, I think it will be more important. Also, there's nothing in the reflect package that says "do not create unbounded numbers of new types because you'll cause a memory leak". Perhaps it should, but I'd much prefer that the issue was actually fixed, even if it takes a while. |
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: https://play.golang.org/p/R6N6IJSzYTD
The text was updated successfully, but these errors were encountered: