长时间使用之后手机变慢

长时间使用之后手机变慢

现象描述:

长时间使用之后手机变慢

抓取java traceview如下显示:

system_server_slowly01

traceview显示是:

WindowsContianer.forAllWindows()占了大量CPU时间.

怀疑是anmimation相关的对象没有释放

用MAT抓取 hprof

有900个WindowStateAnimator对象

Class Name | Objects | Shallow Heap | Retained Heap

com.android.server.wm.WindowStateAnimator| 900 | 201,600 | >= 490,432

被mTokenMap 引用780次

Class Name | Ref. Objects | Shallow Heap | Ref. Shallow Heap | Retained Heap

mTokenMap java.util.HashMap @ 0x1340b950| 780 | 40 | 174,720 | 30,080

代码:
mTokenMap? 没有释放?

// Mapping from a token IBinder to a WindowToken object on this display.
private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap();

private void addWindowToken(IBinder binder, WindowToken token) {
        xxxxx
        xxxxx
        if (token == null) {
            throw new IllegalArgumentException("Can't map null token to display="
                    + getName() + " binder=" + binder);
        }

        mTokenMap.put(binder, token);
        xxxx
        xxxx
}

WindowToken removeWindowToken(IBinder binder) {
    final WindowToken token = mTokenMap.remove(binder);
    if (token != null && token.asAppWindowToken() == null) {
        token.setExiting();
    }
    return token;
}

/** Changes the display the input window token is housed on to this one. */
void reParentWindowToken(WindowToken token) {
    final DisplayContent prevDc = token.getDisplayContent();
    if (prevDc == this) {
        return;
    }
    if (prevDc != null && prevDc.mTokenMap.remove(token.token) != null
            && token.asAppWindowToken() == null) {
        // Removed the token from the map, but made sure it's not an app token before removing
        // from parent.
        token.getParent().removeChild(token);
    }

    addWindowToken(token.token, token);
}

void removeAppToken(IBinder binder) {
    final WindowToken token = removeWindowToken(binder);
    if (token == null) {
        Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
        return;
    }

    final AppWindowToken appToken = token.asAppWindowToken();

    if (appToken == null) {
        Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
        return;
    }

    appToken.onRemovedFromDisplay();
}

  1. 调用:removeWindowToken的地方:
    ./DisplayContent.java: removeAppToken(IBinder binder) {
    ./DisplayContent.java:855: final WindowToken token = removeWindowToken(binder);

./WindowManagerService.java: public void removeWindowToken(IBinder binder, int displayId) {
./WindowManagerService.java:2496: final WindowToken token = dc.removeWindowToken(binder);
./WindowManagerService.java:7530: public void removeWindowToken(IBinder binder, boolean removeWindows, int displayId) {
./WindowManagerService.java:7540: final WindowToken token = dc.removeWindowToken(binder);
./WindowManagerService.java:7549: WindowManagerService.this.removeWindowToken(binder, displayId);

./WindowToken.java:239: mDisplayContent.removeWindowToken(token);


  1. 调用:removeAppToken 的地方:
    ./AppWindowContainerController.java:246: dc.removeAppToken(mToken.asBinder());

从上述查看:
WindowToken 对象和
AppWindowContainerController对象

Class Name | Objects | Shallow Heap | Retained Heap

com.android.server.wm.AppWindowToken| 905 | 181,000 | >= 1,169,272

Class Name | Objects | Shallow Heap | Retained Heap

com.android.server.wm.AppWindowContainerController| 904 | 43,392 | >= 116,032

都是没有释放的.


分析WindowStateAnimator 的释放过程,找出不释放的原因

加上LOG:

WindowToken removeWindowToken(IBinder binder) {
    android.util.Log.w("jackywei","removeWindowToken");
    android.util.Log.w("jackywei",android.util.Log.getStackTraceString(new Throwable()));
    android.util.Log.w("jackywei","++++++++++++++++++++removeWindowToken++++++++++++++++++++");
    final WindowToken token = mTokenMap.remove(binder);
    if (token != null && token.asAppWindowToken() == null) {
        token.setExiting();
    }
    return token;
}

应用died的时候会主动释放:

01-02 12:44:01.223 746 1581 W jackywei: removeWindowToken
01-02 12:44:01.225 746 1581 W jackywei: java.lang.Throwable
01-02 12:44:01.225 746 1581 W jackywei: at com.android.server.wm.DisplayContent.removeWindowToken(DisplayContent.java:832)
01-02 12:44:01.225 746 1581 W jackywei: at com.android.server.wm.DisplayContent.removeAppToken(DisplayContent.java:858)
01-02 12:44:01.225 746 1581 W jackywei: at com.android.server.wm.AppWindowContainerController.removeContainer(AppWindowContainerController.java:246)
01-02 12:44:01.225 746 1581 W jackywei: at com.android.server.am.ActivityRecord.removeWindowContainer(ActivityRecord.java:1001)
01-02 12:44:01.225 746 1581 W jackywei: at com.android.server.am.ActivityStack.removeActivityFromHistoryLocked(ActivityStack.java:4169)
01-02 12:44:01.225 746 1581 W jackywei: at com.android.server.am.ActivityStack.removeHistoryRecordsForAppLocked(ActivityStack.java:4544)
01-02 12:44:01.225 746 1581 W jackywei: at com.android.server.am.ActivityStack.handleAppDiedLocked(ActivityStack.java:5095)
01-02 12:44:01.225 746 1581 W jackywei: at com.android.server.am.ActivityStackSupervisor.handleAppDiedLocked(ActivityStackSupervisor.java:2008)
01-02 12:44:01.225 746 1581 W jackywei: at com.android.server.am.ActivityManagerService.handleAppDiedLocked(ActivityManagerService.java:5413)
01-02 12:44:01.225 746 1581 W jackywei: at com.android.server.am.ActivityManagerService.appDiedLocked(ActivityManagerService.java:5594)
01-02 12:44:01.225 746 1581 W jackywei: at com.android.server.am.ActivityManagerService$AppDeathRecipient.binderDied(ActivityManagerService.java:1641)
01-02 12:44:01.225 746 1581 W jackywei: at android.os.BinderProxy.sendDeathNotice(Binder.java:844)
01-02 12:44:01.226 746 1581 W jackywei: ++++++++++++++++++++removeWindowToken++++++++++++++++++++
01-02 12:44:01.227 746 1581 W jackywei: removeWindowToken
01-02 12:44:01.228 746 1581 W jackywei: java.lang.Throwable
01-02 12:44:01.228 746 1581 W jackywei: at com.android.server.wm.DisplayContent.removeWindowToken(DisplayContent.java:832)
01-02 12:44:01.228 746 1581 W jackywei: at com.android.server.wm.WindowToken.removeImmediately(WindowToken.java:239)
01-02 12:44:01.228 746 1581 W jackywei: at com.android.server.wm.AppWindowToken.removeImmediately(AppWindowToken.java:528)
01-02 12:44:01.228 746 1581 W jackywei: at com.android.server.wm.AppWindowToken.removeIfPossible(AppWindowToken.java:535)
01-02 12:44:01.228 746 1581 W jackywei: at com.android.server.wm.AppWindowToken.onRemovedFromDisplay(AppWindowToken.java:601)
01-02 12:44:01.228 746 1581 W jackywei: at com.android.server.wm.DisplayContent.removeAppToken(DisplayContent.java:871)
01-02 12:44:01.228 746 1581 W jackywei: at com.android.server.wm.AppWindowContainerController.removeContainer(AppWindowContainerController.java:246)
01-02 12:44:01.228 746 1581 W jackywei: at com.android.server.am.ActivityRecord.removeWindowContainer(ActivityRecord.java:1001)
01-02 12:44:01.228 746 1581 W jackywei: at com.android.server.am.ActivityStack.removeActivityFromHistoryLocked(ActivityStack.java:4169)
01-02 12:44:01.228 746 1581 W jackywei: at com.android.server.am.ActivityStack.removeHistoryRecordsForAppLocked(ActivityStack.java:4544)
01-02 12:44:01.228 746 1581 W jackywei: at com.android.server.am.ActivityStack.handleAppDiedLocked(ActivityStack.java:5095)
01-02 12:44:01.228 746 1581 W jackywei: at com.android.server.am.ActivityStackSupervisor.handleAppDiedLocked(ActivityStackSupervisor.java:2008)
01-02 12:44:01.228 746 1581 W jackywei: at com.android.server.am.ActivityManagerService.handleAppDiedLocked(ActivityManagerService.java:5413)
01-02 12:44:01.228 746 1581 W jackywei: at com.android.server.am.ActivityManagerService.appDiedLocked(ActivityManagerService.java:5594)
01-02 12:44:01.228 746 1581 W jackywei: at com.android.server.am.ActivityManagerService$AppDeathRecipient.binderDied(ActivityManagerService.java:1641)
01-02 12:44:01.228 746 1581 W jackywei: at android.os.BinderProxy.sendDeathNotice(Binder.java:844)
01-02 12:44:01.228 746 1581 W jackywei: ++++++++++++++++++++removeWindowToken++++++++++++++++++++

如果应用没有退出,会一直有?

Class Name | Shallow Heap | Retained Heap

com.android.server.wm.WindowState$DeathRecipient @ 0x133e3d40 Native Stack| 16 | 16

Class Name | Objects | Shallow Heap | Retained Heap

com.android.server.wm.WindowState | 900 | 396,000 | >= 2,334,112
com.android.server.wm.WindowStateAnimator | 900 | 201,600 | >= 490,432
com.android.server.wm.WindowState$WindowId | 900 | 28,800 | >= 50,800

com.android.server.wm.WindowState$DeathRecipient| 900 | 14,400 | >= 14,632

下面某个应用:

129,325K: Persistent
     71,069K: com.android.systemui (pid 3694 / activities)
     23,604K: com.android.phone (pid 3862)
     10,641K: com.han.dmfota (pid 952)
      9,753K: com.qualcomm.qti.telephonyservice (pid 3853)
      6,689K: com.qualcomm.telephony (pid 970)
      3,948K: .dataservices (pid 3821)
      3,621K: com.han.tetherEntitlement (pid 947)
 17,922K: Persistent Service
     17,922K: com.android.bluetooth (pid 3483 / activities)
 43,253K: Foreground
     26,516K: com.android.launcher3 (pid 785 / activities)
     10,029K: com.android.chrome (pid 2044 / activities)
      3,663K: com.google.process.gservices (pid 1992)
      3,045K: com.android.partnerbrowsercustomizations (pid 2264)
 81,973K: Visible
     63,027K: com.google.android.gms.persistent (pid 3046)
     12,505K: com.android.printspooler (pid 2361)
      3,243K: com.android.chrome:sandboxed_process0 (pid 2292)
      3,198K: com.qualcomm.qcrilmsgtunnel (pid 574)
115,042K: Perceptible
     76,266K: com.android.mms (pid 3376 / activities)
     38,776K: com.google.android.inputmethod.latin (pid 2321)
  4,831K: A Services
      4,831K: com.facebook.lite:fbns (pid 402)
 18,116K: Previous
     12,914K: com.android.dialer (pid 775 / activities)
      5,202K: android.process.acore (pid 3926)
  7,047K: B Services
      2,947K: com.android.batterywarning (pid 2601)
      2,098K: com.qualcomm.simcontacts (pid 4018)
      2,002K: com.qti.diagrestoreservice (pid 3986)
153,398K: Cached
     22,953K: com.google.android.apps.photos (pid 1307 / activities)
     18,624K: com.android.settings (pid 2041 / activities)
     16,262K: com.google.android.gms (pid 971)
     15,582K: com.android.vending (pid 1183)
     13,022K: com.google.android.gms:snet (pid 1781)
     10,308K: com.android.vending:instant_app_installer (pid 2183)
      9,190K: com.google.android.gms.unstable (pid 2130)
      9,068K: com.google.android.apps.speechservices:search (pid 570)
      8,063K: com.google.android.apps.searchlite (pid 3329)
      7,290K: com.google.android.calendar (pid 2969)
      5,409K: com.facebook.appmanager (pid 1112)
      4,426K: com.facebook.lite (pid 1195)
      3,074K: android.process.media (pid 321)
      2,966K: com.android.providers.calendar (pid 3012)
      2,783K: com.google.process.gapps (pid 699)
      2,356K: com.google.android.partnersetup (pid 3835)
      2,022K: com.han.feedback (pid 2461)

由于都是window产生的问题,先download window

adb shell dumpsys window > window.log

确实有很多对象:

WINDOW MANAGER ANIMATOR STATE (dumpsys window animator)
DisplayContentsAnimator #0:
Window #0: WindowStateAnimator{970b521 com.android.systemui.ImageWallpaper}
Window #1: WindowStateAnimator{4b35d46 com.android.systemui/com.android.systemui.recents.RecentsActivity}
Window #2: WindowStateAnimator{9ace6a5 com.android.mms/com.android.mms.ui.ComposeMessageActivity}
Window #3: WindowStateAnimator{8a51c9c PopupWindow:8bce4ca}
Window #4: WindowStateAnimator{fa27f6a com.android.mms/com.android.mms.ui.ComposeMessageActivity}
Window #5: WindowStateAnimator{9d57434 com.android.bluetooth/com.android.bluetooth.opp.BluetoothOppTransferActivity}
Window #6: WindowStateAnimator{d82825d com.android.bluetooth/com.android.bluetooth.opp.BluetoothOppTransferHistory}
Window #7: WindowStateAnimator{53807d2 com.android.launcher3/com.android.launcher3.SettingsActivity}
Window #8: WindowStateAnimator{9a980a3 com.android.chrome/org.chromium.chrome.browser.webapps.WebApkActivity}
Window #9: WindowStateAnimator{b9b240f com.android.mms/com.android.mms.ui.ConversationList}
Window #10: WindowStateAnimator{b9da56e com.android.mms/com.android.mms.ui.ComposeMessageActivity}
Window #11: WindowStateAnimator{903e4e9 com.android.mms/com.android.mms.ui.ConversationList}
Window #12: WindowStateAnimator{883d970 com.android.mms/com.android.mms.ui.ComposeMessageActivity}
Window #13: WindowStateAnimator{3063fb3 com.android.mms/com.android.mms.ui.ConversationList}
Window #14: WindowStateAnimator{cc31922 com.android.mms/com.android.mms.ui.ComposeMessageActivity}
Window #15: WindowStateAnimator{314c6ed com.android.mms/com.android.mms.ui.ConversationList}
Window #16: WindowStateAnimator{d8ab104 com.android.mms/com.android.mms.ui.ComposeMessageActivity}
Window #17: WindowStateAnimator{8922917 com.android.mms/com.android.mms.ui.ConversationList}
Window #18: WindowStateAnimator{d78f996 com.android.mms/com.android.mms.ui.ComposeMessageActivity}
Window #19: WindowStateAnimator{bb4d0b1 com.android.mms/com.android.mms.ui.ConversationList}
Window #20: WindowStateAnimator{4497758 com.android.mms/com.android.mms.ui.ComposeMessageActivity}
Window #21: WindowStateAnimator{c99843b com.android.mms/com.android.mms.ui.ConversationList}
Window #22: WindowStateAnimator{a0dfaca com.android.mms/com.android.mms.ui.ComposeMessageActivity}
Window #23: WindowStateAnimator{12d0635 com.android.mms/com.android.mms.ui.ConversationList}
Window #24: WindowStateAnimator{a3ac06c com.android.mms/com.android.mms.ui.MessagingPreferenceActivity}
Window #25: WindowStateAnimator{a54b51f com.android.mms/com.android.mms.ui.ConversationList}
Window #26: WindowStateAnimator{78d90be com.android.mms/com.android.mms.ui.ComposeMessageActivity}
Window #27: WindowStateAnimator{87e2b79 com.android.mms/com.android.mms.ui.ConversationList}
Window #28: WindowStateAnimator{97e040 com.android.mms/com.android.mms.ui.ComposeMessageActivity}
Window #29: WindowStateAnimator{17ddfc3 com.android.mms/com.android.mms.ui.ConversationList}
Window #30: WindowStateAnimator{d73ef72 com.android.mms/com.android.mms.ui.ComposeMessageActivity}
Window #31: WindowStateAnimator{d64c47d com.android.mms/com.android.mms.ui.ConversationList}
Window #32: WindowStateAnimator{9ecead4 com.android.mms/com.android.mms.ui.SearchConversationActivity}
Window #33: WindowStateAnimator{db4e827 com.android.mms/com.android.mms.ui.ConversationList}
Window #34: WindowStateAnimator{c220ae6 com.android.mms/com.android.mms.ui.ComposeMessageActivity}

activity 没有释放?

appTokens=[AppWindowToken{ae9bcb7 token=Token{58a53c7 ActivityRecord{3c16106 u0 com.android.mms/.ui.ConversationList t470}}}, AppWindowToken{aaecd1f token=Token{72108be ActivityRecord{4d48379 u0 com.android.mms/.ui.ComposeMessageActivity t470}}}, AppWindowToken{1de4337 token=Token{1c4cce5 ActivityRecord{eafb3dc u0 com.android.mms/.ui.ConversationList t470}}}, AppWindowToken{833e334 token=Token{3150607 ActivityRecord{d5a7446 u0 com.android.mms/.ui.MessagingPreferenceActivity t470}}}, AppWindowToken{2a510e3 token=Token{c22b112 ActivityRecord{b5089d u0 com.android.mms/.ui.ConversationList t470}}}, AppWindowToken{ba134dc token=Token{993754f ActivityRecord{86b73ae u0 com.android.mms/.ui.ComposeMessageActivity t470}}}, AppWindowToken{c6dbbe9 token=Token{bd77727 ActivityRecord{6a34c41 u0 com.android.mms/.ui.ConversationList t470}}}, AppWindowToken{f142eaa token=Token{6cc657f ActivityRecord{70e469e u0 com.android.mms/.ui.MessagingPreferenceActivity t470}}}, AppWindowToken{c75e755 token=Token{4c3f20c ActivityRecord{fa3293f u0 com.android.mms/.ui.ConversationList t470}}}, AppWindowToken{8693e35 token=Token{a956609 ActivityRecord{8942b10 u0 com.android.mms/.ui.ComposeMessageActivity t232}}}, AppWindowToken{5c70d81 token=Token{d9e6568 ActivityRecord{b34208b u0 com.android.mms/.ui.ConversationList t470}}}, AppWindowToken{19989f0 token=Token{e1a6233 ActivityRecord{5e035a2 u0 com.android.mms/.ui.MessagingPreferenceActivity t470}}}, AppWindowToken{aa8ca9e token=Token{33ca0d9 ActivityRecord{5db4f20 u0 com.android.mms/.ui.SmsPreferenceActivity t470}}}, AppWindowToken{1d926be token=Token{4563612 ActivityRecord{e55e874 u0 com.android.mms/.ui.ConversationList t470}}}, AppWindowToken{5757ec3 token=Token{41aaa72 ActivityRecord{dd58b7d u0 com.android.mms/.ui.SearchConversationActivity t470}}}, AppWindowToken{6674364 token=Token{95608f7 ActivityRecord{222ecf6 u0 com.android.mms/.ui.ComposeMessageActivity t499}}}, AppWindowToken{7e1b21c token=Token{53e9f8f ActivityRecord{afbdeee u0 com.android.mms/.ui.ComposeMessageActivity t232}}}, AppWindowToken{2520d2e token=Token{b3b573d ActivityRecord{5010ce7 u0 com.android.mms/.ui.ConversationList t470}}}, AppWindowToken{36f253 token=Token{b267bd5 ActivityRecord{940088c u0 com.android.mms/.ui.ComposeMessageActivity t499}}}, AppWindowToken{bc306e8 token=Token{76eebef ActivityRecord{f8620ce u0 com.android.mms/.ui.ConversationList t470}}}, AppWindowToken{81bd64a token=Token{4a31fb5 ActivityRecord{ebb4fec u0 com.android.mms/.ui.ComposeMessageActivity t470}}}, AppWindowToken{81887e6 token=Token{488b10c ActivityRecord{42ba85e u0 com.android.mms/.ui.ConversationList t470}}}, AppWindowToken{21804fa token=Token{12d1b25 ActivityRecord{eeb531c u0 com.android.mms/.ui.MessagingPreferenceActivity t470}}}, AppWindowToken{4b37307 token=Token{e1b1be ActivityRecord{c1cd940 u0 com.android.mms/.ui.ConversationList t470}}}, AppWindowToken{cfac063 token=Token{b8b6e92 ActivityRecord{c7c4c1d u0 com.android.mms/.ui.ComposeMessageActivity t470}}}, AppWindowToken{1d7627c token=Token{fbd020 ActivityRecord{f47a452 u0 com.android.mms/.ui.ConversationList t470}}}, AppWindowToken{5002c62 token=Token{3d069ac ActivityRecord{3fe3b5f u0 com.android.mms/.ui.ComposeMessageActivity t470}}}, AppWindowToken{9b74477 token=Token{f07a608 ActivityRecord{8affdfa u0 com.android.mms/.ui.ConversationList t470}}}, AppWindowToken{3cc5e55 token=Token{81de50c ActivityRecord{f31083f u0 com.android.mms/.ui.ComposeMessageActivity t470}}}, AppWindowToken{6887990 token=Token{972f01d ActivityRecord{c9c02c7 u0 com.android.mms/.ui.ConversationList t470}}}, AppWindowToken{e305c5b token=Token{2169f6a ActivityRecord{354d955 u0 com.android.mms/.ui.ComposeMessageActivity t470}}}, AppWindowToken{f6fb906 token=Token{9e5f9f5 ActivityRecord{9fa12df u0 com.android.mms/.ui.ConversationList t470}}}, AppWindowToken{eafe567 token=Token{8e1b526 ActivityRecord{b440081 u0 com.android.mms/.ui.ComposeMessageActivity t470}}}, AppWindowToken{e465bf2 token=Token{7dbdc51 ActivityRecord{dfced78 u0 com.android.mms/.ui.ConversationList t470}}}, AppWindowToken{18e58da token=Token{6bad285 ActivityRecord{b89cbfc u0 com.android.mms/.ui.ComposeMessageActivity t470}}}, AppWindowToken{59d2447 token=Token{e8b1675 ActivityRecord{781e9ac u0 com.android.mms/.ui.ConversationList t470}}}, AppWindowToken{7fb9721 token=Token{156b3 ActivityRecord{8f02c22 u0

下面这个hold住了 29 个ComposeMessageActivity

Class Name | Ref. Objects | Shallow Heap | Ref. Shallow Heap | Retained Heap

mArray java.lang.Object[180] @ 0x14d79ce8| 29 | 736 | 19,256 | 736

下面这个hold住了 32 个 ConversationList

Class Name | Ref. Objects | Shallow Heap | Ref. Shallow Heap | Retained Heap

mArray java.lang.Object[180] @ 0x14d79ce8| 32 | 736 | 11,520 | 736

也就是说因为某种原因ConversationList压根没有被释放

排除com.android.mms的问题

adb shell kill -9 com.android.mms

问题依然存在.但是,这些对象都有所减少.

Class Name | Objects | Shallow Heap | Retained Heap

com.android.server.wm.WindowState | 761 | 334,840 | >= 1,964,544
com.android.server.wm.WindowStateAnimator | 761 | 170,464 | >= 414,736
com.android.server.wm.WindowState$WindowId | 761 | 24,352 | >= 43,016

com.android.server.wm.WindowState$DeathRecipient| 761 | 12,176 | >= 12,408

#################################################3

adb shell kill -9 23,153K: com.android.phone (pid 3862)
没有减少:

Class Name | Objects | Shallow Heap | Retained Heap

com.android.server.wm.WindowState | 763 | 335,720 | >= 1,970,008
com.android.server.wm.WindowStateAnimator | 763 | 170,912 | >= 415,824
com.android.server.wm.WindowState$WindowId | 763 | 24,416 | >= 43,128

com.android.server.wm.WindowState$DeathRecipient| 763 | 12,208 | >= 12,440

adb shell kill -9 com.android.systemui
adb shell kill -9 com.android.dialer

都没有减少

Class Name | Objects | Shallow Heap | Retained Heap

com.android.server.wm.WindowState | 761 | 334,840 | >= 1,964,496
com.android.server.wm.WindowStateAnimator | 761 | 170,464 | >= 414,736
com.android.server.wm.WindowState$WindowId | 761 | 24,352 | >= 43,016

com.android.server.wm.WindowState$DeathRecipient| 761 | 12,176 | >= 12,408

Class Name | Ref. Objects | Shallow Heap | Ref. Shallow Heap | Retained Heap

mAppAnimator com.android.server.wm.AppWindowAnimator @ 0x15041678| 1 | 96 | 96 | 288

Type|Name |Value

ref |mDescriptor|java.lang.String @ 0x70c4d0e8

Type|Name|Value

byte|[0] |97
byte|[1] |110
byte|[2] |100
byte|[3] |114
byte|[4] |111
byte|[5] |105
byte|[6] |100
byte|[7] |46
byte|[8] |118
byte|[9] |105
byte|[10]|101
byte|[11]|119
byte|[12]|46
byte|[13]|73
byte|[14]|65
byte|[15]|112
byte|[16]|112
byte|[17]|108
byte|[18]|105
byte|[19]|99
byte|[20]|97
byte|[21]|116
byte|[22]|105
byte|[23]|111
byte|[24]|110
byte|[25]|84
byte|[26]|111
byte|[27]|107
byte|[28]|101

byte|[29]|110

转成字符串:
a n d r o i d . v i e w . I A p p l i c a t i o n T o k e n

日了狗了…哎.

找出申请和释放 WindowStateAnimator的地方,加上LOG,再测试复现

for i in cat all_process.txt | awk '{print $2}';do adb shell kill -9 $i; sleep 30;adb shell am dumpheap 1061 /data/local/tmp/1061.hprof;sleep 30; adb pull /data/local/tmp/1061.hprof; mv 1061.hprof after_$i_1061.hprof;hprof-conv after_$i_1061.hprof after_$i_1061_mat.hprof;done

for i in cat all_process.txt | awk '{print $2}';do echo adb shell kill -9 $i && echo sleep 5 && echo adb shell am dumpheap 1061 /data/local/tmp/1061.hprof && echo sleep 30 && echo adb pull /data/local/tmp/1061.hprof && echo mv 1061.hprof after-$i-1061.hprof && echo hprof-conv after-$i-1061.hprof after-$i-1061_mat.hprof && echo ———————— ; done

for i in cat all_process.txt | awk '{print $2}';do adb shell kill -9 $i && sleep 5 && adb shell am dumpheap 1061 /data/local/tmp/1061.hprof && sleep 30 && adb pull /data/local/tmp/1061.hprof && mv 1061.hprof after-$i-1061.hprof && hprof-conv after-$i-1061.hprof after-$i-1061_mat.hprof && echo ———————— ; done

kill 了 所有 com. 打头的APP,

Class Name | Objects | Shallow Heap | Retained Heap

com.android.server.wm.WindowState | 759 | 333,960 | >= 1,959,816
com.android.server.wm.WindowStateAnimator | 759 | 170,016 | >= 413,568
com.android.server.wm.WindowState$WindowId | 759 | 24,288 | >= 42,904
com.android.server.wm.WindowState$UpdateReportedVisibilityResults| 785 | 18,840 | >= 19,032

com.android.server.wm.WindowState$DeathRecipient | 759 | 12,144 | >= 12,376

还是需要在system_server里面排查未释放的原因.

可以在 ActivityRecord 里面找对应的 strings.
01-01 12:58:16.621 823 3071 W jackywei: this = 48097705,wallpaperTarget.mAppToken = AppWindowToken{50cb356 token=Token{e782efb ActivityRecord{265988a u0 com.android.phone/.EmergencyDialer t7}}}

大部分指向:
com.google.android.apps.searchlite

###################################################################################################

Class Name | Shallow Heap | Retained Heap | Percentage

com.android.server.wm.WindowStateAnimator @ 0x154814c8| 224 | 544 | 0.00%

Type|Name |Value

ref |mAppToken|com.android.server.wm.AppWindowToken @ 0x15480e60

Type|Name |Value

ref |appToken|com.android.server.am.ActivityRecord$Token @ 0x154811b0

Type|Name |Value

ref |weakActivity|java.lang.ref.WeakReference @ 0x154821a8

Type|Name |Value

ref |referent|com.android.server.am.ActivityRecord @ 0x154821f0

Type|Name |Value

ref |appInfo|android.content.pm.ApplicationInfo @ 0x1444b0e0

Type|Name |Value

ref |dataDir|java.lang.String @ 0x1444bc58

Type|Name |Value

ref |value |/data/user/0/com.google.android.apps.searchlite

ref |shadow$klass|class java.lang.String @ 0x706ea708

Type|Name |Value

ref |value|com.google.android.apps.searchlite.SearchLiteApp_Application

Type|Name |Value

ref |value |/data/user/0/com.google.android.apps.searchlite

ref |shadow$klass|class java.lang.String @ 0x706ea708

###################################################################################################

Type|Name |Value

ref |mAppAnimator|com.android.server.wm.AppWindowAnimator @ 0x154811d0

###################################################################################################

###################################################################################################

Class Name | Shallow Heap | Retained Heap | Percentage

com.android.server.wm.WindowStateAnimator @ 0x154838f0| 224 | 544 | 0.00%

Type|Name |Value

ref |mAppAnimator|com.android.server.wm.AppWindowAnimator @ 0x154835f8

Type|Name |Value

ref |mAppToken|com.android.server.wm.AppWindowToken @ 0x15483288

Type|Name |Value

ref |appToken|com.android.server.am.ActivityRecord$Token @ 0x154835d8

Type|Name |Value

ref |referent|com.android.server.am.ActivityRecord @ 0x15484618

Type|Name |Value

ref |appInfo|android.content.pm.ApplicationInfo @ 0x1444b0e0

Type|Name |Value

ref |dataDir|java.lang.String @ 0x1444bc58

Class Name | Ref. Objects | Shallow Heap | Ref. Shallow Heap | Retained Heap

mTokenMap java.util.HashMap @ 0x1439cd50| 1 | 40 | 224 | 27,152

Type |Name |Value

ref |entrySet |null
float|loadFactor |0.75
int |modCount |10233
int |size |787
ref |table |java.util.HashMap$Node[2048] @ 0x1439d1f8
int |threshold |1536
ref |keySet |null
ref |values |java.util.HashMap$Values @ 0x1439d1e8
ref |shadow$klass |class java.util.HashMap @ 0x706ec4c8

int |shadow$monitor|0