F
F
foonfyrick2021-02-18 07:44:15
Android
foonfyrick, 2021-02-18 07:44:15

Memory leak, objects are not deleted?

After creating the database, I check if the objects are deleted, and they are not deleted, all the functions in Dao hang in the profiler, 11 objects are not deleted, even when I closed the database in onStop, nothing changed when I assigned null to all variables, nothing has changed, as 11 objects hung, they hang, I created a new application, and wrote

var context:Context? = null
context= this.applicationContext

I don’t reset the links anywhere, I check that there is not a single object in the profiler, I tried to create listeners without nulling them, and still, there is not a single object in the profiler.
I read that if the reference to the object remains, then the object is not deleted, but then the situation is reversed, no matter what the variable is null or the object, the listener is set to the button or is null, everything is deleted, but as soon as I create the database, neither one of the objects is not removed. Why?
Below, I just created random links, created a listener, I don’t reset anything, there is no leak.
class MainActivity : AppCompatActivity(),View.OnClickListener {
    var context:Context? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        context= this.applicationContext
        button.setOnClickListener(this)
        val a = Test()
        val a2 = Test()
        a.a=4
        a2.b=5
    }

    override fun onClick(v: View?) {
        startActivity(Intent(this,MainActivity2::class.java))

    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Vodakov, 2021-02-18
@foonfyrick

To begin with, check correctly if there is a leak. References should not remain after the garbage collector has finished. What and how to do to search for memory leaks is very well described in this article:
https://habr.com/ru/company/sebbia/blog/243537/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question