diff --git a/media/java/android/media/ImageReader.java b/media/java/android/media/ImageReader.java index 81cc03561d3fe..ec2d4bc9170fa 100644 --- a/media/java/android/media/ImageReader.java +++ b/media/java/android/media/ImageReader.java @@ -157,8 +157,11 @@ public class ImageReader implements AutoCloseable { // Estimate the native buffer allocation size and register it so it gets accounted for // during GC. Note that this doesn't include the buffers required by the buffer queue // itself and the buffers requested by the producer. - mEstimatedNativeAllocBytes = ImageUtils.getEstimatedNativeAllocBytes(width, height, format, - maxImages); + // Only include memory for 1 buffer, since actually accounting for the memory used is + // complex, and 1 buffer is enough for the VM to treat the ImageReader as being of some + // size. + mEstimatedNativeAllocBytes = ImageUtils.getEstimatedNativeAllocBytes( + width, height, format, /*buffer count*/ 1); VMRuntime.getRuntime().registerNativeAllocation(mEstimatedNativeAllocBytes); } diff --git a/media/java/android/media/ImageWriter.java b/media/java/android/media/ImageWriter.java index 83a4f17ffccb2..b142ddd9fbff5 100644 --- a/media/java/android/media/ImageWriter.java +++ b/media/java/android/media/ImageWriter.java @@ -138,11 +138,14 @@ public class ImageWriter implements AutoCloseable { // Estimate the native buffer allocation size and register it so it gets accounted for // during GC. Note that this doesn't include the buffers required by the buffer queue // itself and the buffers requested by the producer. + // Only include memory for 1 buffer, since actually accounting for the memory used is + // complex, and 1 buffer is enough for the VM to treat the ImageWriter as being of some + // size. Size surfSize = SurfaceUtils.getSurfaceSize(surface); int format = SurfaceUtils.getSurfaceFormat(surface); mEstimatedNativeAllocBytes = ImageUtils.getEstimatedNativeAllocBytes(surfSize.getWidth(),surfSize.getHeight(), - format, maxImages); + format, /*buffer count*/ 1); VMRuntime.getRuntime().registerNativeAllocation(mEstimatedNativeAllocBytes); }