Skip to content

FFITypes for non-base classes are never removed from typeInfoMap, causing the Cleaner thread to loop forever #1633

@emarteca

Description

@emarteca

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:

  1. Change the way FFITypes for Structures are made, so they don't have any underlying Memory.
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions