From 13bd771c993f96a06add4057c5f5d5be7ac4b42a Mon Sep 17 00:00:00 2001 From: Svetoslav Date: Fri, 19 Sep 2014 18:18:04 -0700 Subject: [PATCH] Fix memory leak in accessibility cache. We were not clearing the cache if window state change event is fired which was the behavior before adding the window inspection APIs. As a result if no accessibility service cares about windows we get a leek. Also when the accessibiilty service cares about windows we were not clearing all windows nodes from the cache. Now if a windows change or a window state change event is recived we clear the cache. bug:17589257 Change-Id: I8c416fbcab623160c6f505128b9fca713fcc6623 --- .../accessibility/AccessibilityCache.java | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/core/java/android/view/accessibility/AccessibilityCache.java b/core/java/android/view/accessibility/AccessibilityCache.java index ead757eb9a7db..a218e4dc0b922 100644 --- a/core/java/android/view/accessibility/AccessibilityCache.java +++ b/core/java/android/view/accessibility/AccessibilityCache.java @@ -63,22 +63,6 @@ final class AccessibilityCache { } } - public void clearWindows() { - synchronized (mLock) { - final int windowCount = mWindowCache.size(); - for (int i = windowCount - 1; i >= 0; i--) { - AccessibilityWindowInfo window = mWindowCache.valueAt(i); - if (window != null) { - if (DEBUG) { - Log.i(LOG_TAG, "Removing window: " + window.getId()); - } - window.recycle(); - mWindowCache.removeAt(i); - } - } - } - } - /** * Notifies the cache that the something in the UI changed. As a result * the cache will either refresh some nodes or evict some nodes. @@ -115,8 +99,9 @@ final class AccessibilityCache { clearSubTreeLocked(event.getWindowId(), event.getSourceNodeId()); } break; - case AccessibilityEvent.TYPE_WINDOWS_CHANGED: { - clearWindows(); + case AccessibilityEvent.TYPE_WINDOWS_CHANGED: + case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED: { + clear(); } break; } } @@ -287,7 +272,7 @@ final class AccessibilityCache { private void clearNodesForWindowLocked(int windowId) { if (DEBUG) { - Log.i(LOG_TAG, "clearWindowLocked(" + windowId + ")"); + Log.i(LOG_TAG, "clearNodesForWindowLocked(" + windowId + ")"); } LongSparseArray nodes = mNodeCache.get(windowId); if (nodes == null) { @@ -440,7 +425,7 @@ final class AccessibilityCache { } } if (!childOfItsParent) { - Log.e(LOG_TAG, "Invalid parent-child ralation between parent: " + Log.e(LOG_TAG, "Invalid parent-child relation between parent: " + nodeParent + " and child: " + node); } } @@ -452,7 +437,7 @@ final class AccessibilityCache { if (child != null) { AccessibilityNodeInfo parent = nodes.get(child.getParentNodeId()); if (parent != node) { - Log.e(LOG_TAG, "Invalid child-parent ralation between child: " + Log.e(LOG_TAG, "Invalid child-parent relation between child: " + node + " and parent: " + nodeParent); } }