Closed BwackNinja closed 4 months ago
Thanks for logging these issues.
I made some changes to remove non-GObject classes from the InstanceCache, but it is still work in progress.
One problem that I haven't figured out yet, is how to treat interfaces. When a method returns an interface, is it a GObject or not? AFAIK that information is only available at runtime.
I think this should work correctly now (in the development branch), but I'm having trouble creating testcases.
Do you have a testcase that I can use?
I tested it with Gtk Expression and that works. This will be fixed in the next release.
Fantastic. Thanks for resolving this so quickly.
I was having trouble thinking of a testcase that would reliably fail before your changes.
Since commit https://github.com/jwharm/java-gi/commit/6326ea19daa9e82972893a1368c08735dd5b37df TypeInstances are successfully added to the InstanceCache. This is a problem because only GObjects have a ToggleNotify, which is the only way an instance is removed from the InstanceCache. This causes a java.lang.ClassCastException when an object of a different type occupies a previously used memory address because the old java object will be returned.
An example TypeInstance that isn't a GObject is a RenderNode. If they are not unref'd, then there will be a memory leak, but if they are then an exception will eventually occur.
I've patched it locally and it works for me, but haven't tried this with the development branch, which puts it into the strongReferences map now rather than the weakReferences map.