[关闭]
@act262 2017-05-24T14:25:20.000000Z 字数 577 阅读 1065

Message

AndroidSource


Message 回收机制

  1. void recycleUnchecked() {
  2. // Mark the message as in use while it remains in the recycled object pool.
  3. // Clear out all other details.
  4. flags = FLAG_IN_USE;
  5. what = 0;
  6. arg1 = 0;
  7. arg2 = 0;
  8. obj = null;
  9. replyTo = null;
  10. sendingUid = -1;
  11. when = 0;
  12. target = null;
  13. callback = null;
  14. data = null;
  15. synchronized (sPoolSync) {
  16. if (sPoolSize < MAX_POOL_SIZE) {
  17. // 把当前的Message插入表头
  18. next = sPool;
  19. sPool = this;
  20. sPoolSize++;
  21. }
  22. }
  23. }
  1. public static Message obtain() {
  2. synchronized (sPoolSync) {
  3. if (sPool != null) {
  4. // 从表头取出一个Message,原先下个的Message成为新的表头
  5. Message m = sPool;
  6. sPool = m.next;
  7. m.next = null;
  8. m.flags = 0; // clear in-use flag
  9. sPoolSize--;
  10. return m;
  11. }
  12. }
  13. return new Message();
  14. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注