Skip to content
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

[KMP] Memory leak found in PublicKey #4096

Open
10gic opened this issue Nov 5, 2024 · 3 comments
Open

[KMP] Memory leak found in PublicKey #4096

10gic opened this issue Nov 5, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@10gic
Copy link
Contributor

10gic commented Nov 5, 2024

Describe the bug
I found a memory leak in PublicKey within the Kotlin package of Wallet Core.

To Reproduce
The following code can trigger a memory leak:

println("Test started")
val publicKeyHex =
    @Suppress("ktlint:standard:max-line-length")
    "044ba28b11af1561042b03b9d0f940446315af11358aa12d798050b3cf76265dab0f48b22ea1fc1f9560c969b966221f2821b746c4e56efaeaeec8689caf5843c9"
var i = 1
val publicKeyByteArray = publicKeyHex.hexToByteArray()
while (i <= 10_000_000) {
    val publicKey = PublicKey(publicKeyByteArray, PublicKeyType.SECP256k1Extended)
    if (i % 20_000 == 0) {
        println("Test case $i run")
    }
    i++
}
println("Test completed")

Expected behavior
No memory leak.

Screenshots
Memory Profiler Screenshot:
kmp-memory-leak-public-key

Additional context

@10gic 10gic added the bug Something isn't working label Nov 5, 2024
@satoshiotomakan
Copy link
Collaborator

Hi @10gic, this issue duplicates #4021
As I mentioned before, GC doesn't have time to trigger the ReferenceQueue to clean up the memory. But in real life there shouldn't be the memory leak.
However, if there is something I'm wrong with, or miss something, I'd be happy to know

@satoshiotomakan satoshiotomakan closed this as not planned Won't fix, can't repro, duplicate, stale Nov 5, 2024
@10gic
Copy link
Contributor Author

10gic commented Nov 5, 2024

The root cause is completely different, so I opened a new bug.

@satoshiotomakan
Copy link
Collaborator

I see @10gic, thanks. I'm investigating the bug, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants