-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Kotlin multiplatform leaking memory #4037
Conversation
Binary size comparison➡️ aarch64-apple-ios: 12.13 MB ➡️ aarch64-apple-ios-sim: 12.14 MB ➡️ aarch64-linux-android: 15.57 MB ➡️ armv7-linux-androideabi: 13.29 MB ➡️ wasm32-unknown-emscripten: 11.03 MB |
Hi @vcoolish, glad to see this fixed. Could you provide some test data after the fix? |
attached android and ios data, for JS I couldn't get memory usage increase yet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the fix! I have one note
init { | ||
Thread { | ||
try { | ||
doDeletes() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we spawn a new thread for each instance of HDWallet, AnyAddress etc?
I saw examples do the same, but it's not optimal. What if we have one PhantomReferenceRegistry
singleton class that spawns one thread, and AnyAddress.init()
and HDWallet.init()
just register the nativeHandle
with a corresponding delete function.
So the pseudocode will look like:
class AnyAddress {
init {
PhantomReferenceRegistry.getOrCreate().register(nativeHandle, TWAnyAddressDelete)
}
}
class PhantomReferenceRegistry {
init {
Thread {
doDeletes()
}
}
// Sends a pair of `nativeHandle` and `TWAnyAddressDelete(nativeHandle)` to the spawned thread.
private val channel: Channel<Pair<Long, (Long)>>
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for suggestion, done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me!
Fixes #4021
Android:
iOS: