VEX-6030: Further prevent memory crashes (#15)
This PR is intended to prevent memory crashes when the free memory runs out Jira: VEX-6030 https://jira.tenkasu.net/browse/VEX-6030 Velocity PR: crunchyroll/velocity#2043 By forcefully calling the garbage collector the memory crashes, specially on lower resolutions (<720p) are gone on devices with 2GB of ram or less and Android 6, also testing 3GB Android 7 with this patch, so far is working as intended Reviews Major reviewer (domain expert): @nickfujita Minor reviewer: @jctorresM
This commit is contained in:
commit
aa63361695
@ -423,6 +423,7 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
|
|
||||||
private class RNVLoadControl extends DefaultLoadControl {
|
private class RNVLoadControl extends DefaultLoadControl {
|
||||||
private int availableHeapInBytes = 0;
|
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) {
|
public RNVLoadControl(DefaultAllocator allocator, int minBufferMs, int maxBufferMs, int bufferForPlaybackMs, int bufferForPlaybackAfterRebufferMs, int targetBufferBytes, boolean prioritizeTimeOverSizeThresholds, int backBufferDurationMs, boolean retainBackBufferFromKeyframe) {
|
||||||
super(allocator,
|
super(allocator,
|
||||||
minBufferMs,
|
minBufferMs,
|
||||||
@ -433,6 +434,7 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
prioritizeTimeOverSizeThresholds,
|
prioritizeTimeOverSizeThresholds,
|
||||||
backBufferDurationMs,
|
backBufferDurationMs,
|
||||||
retainBackBufferFromKeyframe);
|
retainBackBufferFromKeyframe);
|
||||||
|
runtime = Runtime.getRuntime();
|
||||||
ActivityManager activityManager = (ActivityManager) themedReactContext.getSystemService(themedReactContext.ACTIVITY_SERVICE);
|
ActivityManager activityManager = (ActivityManager) themedReactContext.getSystemService(themedReactContext.ACTIVITY_SERVICE);
|
||||||
availableHeapInBytes = (int) Math.floor(activityManager.getMemoryClass() * maxHeapAllocationPercent * 1024 * 1024);
|
availableHeapInBytes = (int) Math.floor(activityManager.getMemoryClass() * maxHeapAllocationPercent * 1024 * 1024);
|
||||||
}
|
}
|
||||||
@ -447,6 +449,11 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
if (isHeapReached) {
|
if (isHeapReached) {
|
||||||
return false;
|
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);
|
return super.shouldContinueLoading(playbackPositionUs, bufferedDurationUs, playbackSpeed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user