-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
The FFIType
class has a static WeakHashMap
of type information, the typeInfoMap
. Since it is a weak map, key-value pairs would be removed if the key was garbage collected. However, since the keys in this map are Classes, they are extremely unlikely to ever be collected.
For classes that are Structures, the FFIType stored in the typeInfoMap
wraps the structure object itself, here. However, when the FFIType is a Structure, there is underlying Memory
in it, which has a MemoryDisposer
registered on it.
Since the Class is never unloaded, the FFType cannot be garbage collected either -- however, the Cleaner thread expects to be able to clean up its Memory, and so it will loop forever waiting to be able to clean it.
Potential solutions: I am not sure the best way to go about fixing this problem, but there are two approaches I think of first:
- Change the way FFITypes for Structures are made, so they don't have any underlying Memory.
- Use a different, special kind of Memory for FFITypes, that has no cleaner registration. Since this memory corresponds to a Class, I think it could be safe to assume there are a limited number of classes being loaded.
Let me know what you think. I''m trying to hack around this problem right now in my project, and will update this issue when I have a temporary solution too.