2

I post this question because i wanna know if my thoughts are right about the basics.

What should be clear is that the UI-Thread contains a MessageQueue, which is associated with a Looper to get messages/runnables out of the queue for processing.

Furthermore a Handler sends messages/runnables to the Looper, which integrates the object in the MessageQueue.

If im right the MessageQueue is the stack and the Looper is the caretaker of the incoming and outgoing objects.

This leads to my next question. If a message object is processed by the UI-Thread, it will be recycled to the global message pool. But theres no explicit documentation about this. Is there a specific size for this message pool? Is it expandable/shrinkable if i send/obtain messages?

If this would be true the pool could dry out by obtaining to many messages. And i cant believe this. Think about a situation where you have to obtain some messages without sending them back for recycling in a specific time period.

Edited to make it more understandable.

Steve Benett
  • 12,843
  • 7
  • 59
  • 79

1 Answers1

3

You can take a look at the source code of Handler and Message in the framework to see the details on how this works.

In short, the pool is a linked list of Message objects (up to MAX_POOL_SIZE) that will be filled by the the recycle() method. The obtain() methods simply checked the pool first of any available Message that can be reused and just allocate a new one if none is available.

Joe
  • 14,039
  • 2
  • 39
  • 49