Skip to content
Commit 8e88e955 authored by Hui Yu's avatar Hui Yu
Browse files

Fix memory leak in TimeBase.mObservers list.

Leaks happen in following places:
1. Not all timer/counter in Uid class are detached from TimeBase when
the Uid object is destructed.
2. When Uid object is removed from mUidStats list in
onUserRemovedLocked, removeUidStatsLocked, readLocked, All
timer/counter in Uid class are not detached from TimeBase.
3. When timer/counter in Uid class is reassigned, the previous
timer/counter object is not detached.

Performance improvement:
The mObservers list in TimeBase object of BatteryStatsImpl can have
size up like 20k, the list type is ArrayList, remove() method on
ArrayList is very slow. For long mObservers list, we change to use
HashSet as container. The mObservers list in TimeBase object of Uid
is short, it continues to use ArrayList as container.

Fix: 80443940
Test: "adb shell cmd battery unplug" and "adb shell cmd battery set ac 1",
observe memory usage from Android Monitor.

Change-Id: I2001ca390a0a86a32082e1012dde4b831f1e7d04
parent aaaedf21
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