Specific release windowless surface in core.

So the surface layer can be removed once shell side also remove it,
instead of waiting for GC happen in system server.

Bug: 345021645
Test: trigger PB animation multiple times, then verify windowless
surface wont' remain in offscreen hierarchy.

Change-Id: I75d0cd1264c11c67d0b4fa22485c2f7559852a57
diff --git a/services/core/java/com/android/server/wm/BackNavigationController.java b/services/core/java/com/android/server/wm/BackNavigationController.java
index 0febec9..2972190 100644
--- a/services/core/java/com/android/server/wm/BackNavigationController.java
+++ b/services/core/java/com/android/server/wm/BackNavigationController.java
@@ -1366,8 +1366,6 @@
                                         ? task.getSurfaceControl()
                                         : mAdaptors[0].mTarget.getSurfaceControl());
                     }
-                    // remove starting surface.
-                    mStartingSurface = null;
                 }
             }
 
@@ -1384,7 +1382,10 @@
                         .removeWindowlessStartingSurface(mRequestedStartingSurfaceId,
                                 !openTransitionMatch);
                 mRequestedStartingSurfaceId = INVALID_TASK_ID;
-                mStartingSurface = null;
+                if (mStartingSurface != null && mStartingSurface.isValid()) {
+                    mStartingSurface.release();
+                    mStartingSurface = null;
+                }
             }
         }