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

Serious memory leak (Android liquidcore) #227

Open
here-nerd opened this issue Jan 14, 2022 · 4 comments
Open

Serious memory leak (Android liquidcore) #227

here-nerd opened this issue Jan 14, 2022 · 4 comments

Comments

@here-nerd
Copy link

here-nerd commented Jan 14, 2022

I use LiquidCore 0.7.10 in my Android app and I have experienced memory leak when calling a JS function from Kotlin code. I am sharing with you my dummy Android app to show how easy it is to reproduce the issue. I have a hard time to believe that this issue is real because that would mean liquidcore would become unusable for any Android app.. it's a time bomb. Please take a look and share your thought.

class MainActivity : AppCompatActivity() {    
   // 1000 char-long text
    private val plaintext = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val button = findViewById<Button>(R.id.button)

        button?.setOnClickListener{
            testDummy()
        }
    }

    private fun testDummy() {
        val context = JSContext()
        context.evaluateScript(applicationContext.resources.openRawResource(
            R.raw.myjscode).bufferedReader().use { it.readText() })
        val lib = context!!.evaluateScript("myCode").toObject()
        val aFunction = lib.property("test").toFunction()
        for (i in 0..10000) {
            aFunction.call(context, plaintext).toString()
        }
    }
}

this is my javascript code:

var myCode;

myCode = {
    test: (plainText) => { }
}

Note: I use a relatively long string (1000 chars) and 10000 iterations in order to make it easily visible when memory profiling. The point is the memory consumption is growing and is not garbage collected.. even with e.g. 10 char-long string.

To reproduce the issue, run the app and keep tapping the 'RUN TEST' button --> the memory profile shows this:
image
The memory of 'Others' kept growing. Forcing garbage collection didn't help.
Heap dump shows that the number of WeakReferences kept growing too:
image

Eventually, the app would crash with this error message:
"A/libc: Fatal signal 4 (SIGILL), code 2 (ILL_ILLOPN), fault addr 0xb4cbd4d4 in tid 22743 (e.myapplication), pid 22743 (e.myapplication)"

The code can be downloaded from here.

@here-nerd here-nerd changed the title Memory leak (Android liquidcore) Serious memory leak (Android liquidcore) Jan 27, 2022
@here-nerd
Copy link
Author

here-nerd commented Mar 2, 2022

@ericwlange Is this project still maintained?

@ericwlange
Copy link
Member

ericwlange commented Mar 6, 2022 via email

@here-nerd
Copy link
Author

here-nerd commented Mar 11, 2022

@ericwlange thank you for your reply and your contributions to the project so far.

Could you please update your README sharing with your users and contributors that the project needs a new maintainer?
or
Would you recommend an alternative project instead?

@pcfreak30
Copy link

@ericwlange Thats a shame. I just found this as a route to run a js based code base in the background on a phone for accessing the web3 internet. Could enable a lot.

Please update the project then so others are aware, but it would be nice if you got funding for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants