Skip to content

Commit

Permalink
force garbage collector when free memory reaches 0
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-rivero committed Nov 17, 2021
1 parent 292b539 commit 2b310cb
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 2b310cb

Please sign in to comment.