wm: recycle bitmaps immediately in TaskSnapshotPersister

Bitmap created in TaskSnapshotPersister are very short lived and
shouldn't be left around in the Java heap.

Test: boot, switch apps, works
bug 117795621

Exempt-From-Owner-Approval: approved in another branch
Change-Id: I4b5e0db50c2b7adaa71cb0d22535c1b37c7523e8
diff --git a/services/core/java/com/android/server/wm/TaskSnapshotPersister.java b/services/core/java/com/android/server/wm/TaskSnapshotPersister.java
index 21e807e..6fd1795 100644
--- a/services/core/java/com/android/server/wm/TaskSnapshotPersister.java
+++ b/services/core/java/com/android/server/wm/TaskSnapshotPersister.java
@@ -17,6 +17,7 @@
 package com.android.server.wm;
 
 import static android.graphics.Bitmap.CompressFormat.*;
+
 import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
 import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
 
@@ -361,6 +362,7 @@
 
             // For snapshots with reduced resolution, do not create or save full sized bitmaps
             if (mSnapshot.isReducedResolution()) {
+                swBitmap.recycle();
                 return true;
             }
 
@@ -373,6 +375,8 @@
                 Slog.e(TAG, "Unable to open " + file + " for persisting.", e);
                 return false;
             }
+            reduced.recycle();
+            swBitmap.recycle();
             return true;
         }
     }