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
Loading
Please register or sign in to comment