Skip to content
Commit 3488f1af authored by Hui Yu's avatar Hui Yu
Browse files

Use ArraySet for the list of observer WeakReference.

On a real device, the mObservers list size can be close to 20k.
Previously mObservers is an ArrayList of strong Reference and there
is memory leak from it. This is why we changed to WeakReference. It
takes 2ms to remove an Reference element from a 20k ArrayList. But It
takes 9ms to remove a WeakReference element from a 20k ArrayList
. This increases chance of ANR. Now we change from ArrayList to
ArraySet, removing a WeakReference element from a 20k ArraySet only
takes 0.1ms. The memory difference between ArrayList and ArraySet is
minimum.

Fix: 111555898
Test: compare time takes to remove WeakReference element from ArrayList
and ArraySet.

Change-Id: If77633549197bcb3cf5269b537288f0189f2fcf3
parent 81b6aee2
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment