- The memory leak is not due to the Activity being held, but is essentially due to parsing GC_ROOT. Do you think the anonymous inner class passed in by setOnClickListener will leak? GC_ROOT includes active threads, objects referenced in the virtual machine stack, objects referenced in JNI (Native methods) in the local method stack, objects referenced in static properties of classes in the method area, and objects referenced in constants in the method area. In addition, coroutine leak and thread leak are essentially a kind of memory leak.
- The ViewModel in Jetpack is not designed to implement MVVM, it is designed to solve the problem of data loss caused by Activity destruction and reconstruction due to Configuration changes. The implementation of MVVM is DataBinding in Jetpack. But we can’t rule out Google adding MVVM capabilities to the ViewModel in the future.
- MessageQueue in the Message mechanism is not a queue in the strict sense. According to the definition of the data structure of the queue, a queue is a linear table that can only be inserted from the end of the queue and removed from the head of the queue, while MessageQueue inserts messages from different positions according to the WHEN field of the Message. Therefore, in a strict sense, MessageQueue is just an ordinary linear list, which is exactly a one-way linked list.