在Kotlin中,可以使用伴生对象创建单例:
class MyClass {
companion object {
fun doSomething() {
}
}
}
According to the Kotlin docs, it states:
Note that, even though the members of companion objects look like static members in other languages, at runtime those are still instance members of real objects...
https://kotlinlang.org/docs/reference/object-declarations.html
Does this mean that after using a function in the companion object, the instance of the class (MyClass) remains in memory for the entire lifecycle of the app? Is there a way in Android Studio to check to see if this is the case?