From 2b310cbf7ef5d07934d348c6f731328e164de195 Mon Sep 17 00:00:00 2001 From: Gabriel Rivero Date: Tue, 16 Nov 2021 20:35:30 -0400 Subject: [PATCH 1/2] force garbage collector when free memory reaches 0 --- .../java/com/brentvatne/exoplayer/ReactExoplayerView.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index ea27b947ee..8843702e64 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -423,6 +423,7 @@ private void reLayout(View view) { private class RNVLoadControl extends DefaultLoadControl { private int availableHeapInBytes = 0; + private Runtime runtime; public RNVLoadControl(DefaultAllocator allocator, int minBufferMs, int maxBufferMs, int bufferForPlaybackMs, int bufferForPlaybackAfterRebufferMs, int targetBufferBytes, boolean prioritizeTimeOverSizeThresholds, int backBufferDurationMs, boolean retainBackBufferFromKeyframe) { super(allocator, minBufferMs, @@ -433,6 +434,7 @@ public RNVLoadControl(DefaultAllocator allocator, int minBufferMs, int maxBuffer prioritizeTimeOverSizeThresholds, backBufferDurationMs, retainBackBufferFromKeyframe); + runtime = Runtime.getRuntime(); ActivityManager activityManager = (ActivityManager) themedReactContext.getSystemService(themedReactContext.ACTIVITY_SERVICE); availableHeapInBytes = (int) Math.floor(activityManager.getMemoryClass() * maxHeapAllocationPercent * 1024 * 1024); } @@ -447,6 +449,11 @@ public boolean shouldContinueLoading(long playbackPositionUs, long bufferedDurat if (isHeapReached) { return false; } + if (runtime.freeMemory() == 0) { + Log.w("ExoPlayer Warning", "free memory reached 0, forcing garbage collection"); + runtime.gc(); + return false; + } return super.shouldContinueLoading(playbackPositionUs, bufferedDurationUs, playbackSpeed); } } From ab202c96b6f68ca89304dcb3fccd49d526c5df95 Mon Sep 17 00:00:00 2001 From: Gabriel Rivero Date: Tue, 16 Nov 2021 21:40:38 -0400 Subject: [PATCH 2/2] typo --- .../main/java/com/brentvatne/exoplayer/ReactExoplayerView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index 8843702e64..eb4dfa8de3 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -450,7 +450,7 @@ public boolean shouldContinueLoading(long playbackPositionUs, long bufferedDurat return false; } if (runtime.freeMemory() == 0) { - Log.w("ExoPlayer Warning", "free memory reached 0, forcing garbage collection"); + Log.w("ExoPlayer Warning", "Free memory reached 0, forcing garbage collection"); runtime.gc(); return false; }