-
Notifications
You must be signed in to change notification settings - Fork 30
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
JavaKit: Java maintaining references to Swift values without Panama #168
Comments
? We'll absolutely be shipping some libraries or plugins as jars eventually. |
We should not be using finalizers if we can help it. Please have a look at SwiftKit and the SwiftArena, this is the way to manage swift resources in Java, it's a more predictable modern way of doing so. There is an |
Ah, just thought that would make the build process even more of a pain the proverbial! |
Can we rephrase this ticket in terms of the problem to solve rather than propose the solution? The "modern way" is |
Sure. I wasn't aware of SwiftArena. But it looks like it requires Panorama, whereas Android I believe is still at JDK 17. Will confirm shortly. |
So funnily enough I think we should pursue making that lib have some parts which are usable on older platforms as well, and that may include the |
Thanks for the rename! :) |
Sounds good. I may not have the cycles to help on this but I'll have a think! |
Pleasure. Here I was thinking I had thought of something you hadn't. |
I'm sure you'll bump into a lot of things we've not thought about yet, this one I had a sneaky plan for though :) |
The biggest remaining issue for me is object/JNIEnv affinity, but there's an open issue for that 😉 |
Amusingly SwiftKit uses _typeByName() which I proposed nearly ten years ago. Must be getting old. |
We will actually stop using that as soon as I finish my “extract build plugin” PR, but yeah it’s still hidden api… |
Of potential note: https://github.com/vova7878/PanamaPort |
Oh that's very interesting, perhaps a route we could attempt huh 🤔 Thanks for sharing! |
I think I will just migrate my code to use Cleanable instead of finalize(). I don't have the time right now to unpick the back-portable bits of SwiftArena. |
Yeah that would already be a nice step! And that’ll then be easy to hook into the arena :) I can look at these later on |
Pasted in code/links to (edited) original post in case you feel like taking a look. Perhaps I should add C JNI wrappers for |
Yeah that's right. This is done by https://github.com/swiftlang/swift-java/blob/main/SwiftKit/src/main/java/org/swift/swiftkit/AutoSwiftMemorySession.java#L47-L51 already, no need to reinvent -- just reorganize the code so this part of it lives in a non-FFM dependent part of the project. We can make some I think we should look into sharing the infrastructure basically |
Sounds good. Won't be able to look at this again for a few weeks. |
Edit: something I have found useful. Refactored to not use
finalize()
, and added links. Essentially:https://github.com/PADL/FlutterSwift/blob/main/Sources/FlutterAndroid/com/padl/FlutterAndroid/SwiftHeapObjectHolder.java
https://github.com/PADL/FlutterSwift/blob/main/Sources/FlutterAndroid/SwiftHeapObjectHolderNativeMethods.swift
The text was updated successfully, but these errors were encountered: