react-native-video: ExoPlayer has memory leakage problem

Bug

Finally, the application went crashed with a number of out of memory exceptions, after many or several times (depending on the device performance) of mount/unmount/hot-reload operations. This only happens on ExoPlayer, not so on Android Media Player.

Here is a cut of my Android Logcat:

2022-07-14 22:13:31.287 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":1.954}])
2022-07-14 22:13:31.288 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([4897,"onVideoEnd",null])
2022-07-14 22:13:33.027 24490-24490/? W/unknown:WrappingUtils: Don't know how to round that drawable: com.facebook.react.views.image.ReactImageDownloadListener$EmptyDrawable@56846f1
2022-07-14 22:13:33.028 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":4.777}])
2022-07-14 22:13:33.028 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":4.134}])
2022-07-14 22:13:33.028 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":3.032}])
2022-07-14 22:13:33.028 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":3.91}])
2022-07-14 22:13:33.028 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":5.186}])
2022-07-14 22:13:33.028 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([4897,"onVideoProgress",{"seekableDuration":2.96,"playableDuration":2.96,"currentTime":2.971}])
2022-07-14 22:13:33.028 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([4897,"onVideoProgress",{"seekableDuration":2.96,"playableDuration":2.96,"currentTime":2.971}])
2022-07-14 22:13:33.028 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":6.188}])
2022-07-14 22:13:33.624 24490-28550/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:33.624 24490-28550/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 42144 free bytes and 41KB until OOM, target footprint 402653184, growth limit 402653184" (VmSize 50160224 kB)
2022-07-14 22:13:34.800 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":4.01}])
2022-07-14 22:13:35.039 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":4.211}])
2022-07-14 22:13:35.301 24490-28550/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:35.301 24490-28550/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 3816 free bytes and 3816B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 50142736 kB)
2022-07-14 22:13:35.488 24490-28529/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:35.488 24490-28529/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 14888 free bytes and 14KB until OOM, target footprint 402653184, growth limit 402653184" (VmSize 50142736 kB)
2022-07-14 22:13:35.829 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([4897,"onVideoProgress",{"seekableDuration":2.96,"playableDuration":2.96,"currentTime":2.971}])
2022-07-14 22:13:35.830 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":7.798}])
2022-07-14 22:13:36.422 24490-28561/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:36.423 24490-28561/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 13472 free bytes and 13KB until OOM, target footprint 402653184, growth limit 402653184" (VmSize 50142736 kB)
2022-07-14 22:13:36.969 24490-28548/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:36.969 24490-28548/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 14256 free bytes and 13KB until OOM, target footprint 402653184, growth limit 402653184" (VmSize 50055296 kB)
2022-07-14 22:13:37.294 24490-28545/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:37.294 24490-28545/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 14496 free bytes and 14KB until OOM, target footprint 402653184, growth limit 402653184" (VmSize 50055296 kB)
2022-07-14 22:13:37.651 24490-28529/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:37.651 24490-28529/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65552 byte allocation with 15952 free bytes and 15KB until OOM, target footprint 402653184, growth limit 402653184" (VmSize 50055296 kB)
2022-07-14 22:13:38.289 24490-28560/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:38.290 24490-28560/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 5184 free bytes and 5184B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 50037808 kB)
2022-07-14 22:13:38.475 24490-28529/? E/LoadTask: OutOfMemory error loading stream
    java.lang.OutOfMemoryError: Failed to allocate a 65552 byte allocation with 15952 free bytes and 15KB until OOM, target footprint 402653184, growth limit 402653184
        at com.google.android.exoplayer2.upstream.DefaultAllocator.allocate(DefaultAllocator.java:102)
        at com.google.android.exoplayer2.source.SampleQueue.preAppend(SampleQueue.java:624)
        at com.google.android.exoplayer2.source.SampleQueue.sampleData(SampleQueue.java:544)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.readSample(Mp4Extractor.java:533)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.read(Mp4Extractor.java:187)
        at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:898)
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:381)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:929)
2022-07-14 22:13:38.478 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":2.506}])
2022-07-14 22:13:38.480 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":5.936}])
2022-07-14 22:13:38.480 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":10.574}])
2022-07-14 22:13:38.480 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":9.702}])
2022-07-14 22:13:38.480 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":6.611}])
2022-07-14 22:13:38.481 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":5.186}])
2022-07-14 22:13:38.481 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([4897,"onVideoProgress",{"seekableDuration":2.96,"playableDuration":2.96,"currentTime":9.535}])
2022-07-14 22:13:38.481 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([4897,"onVideoProgress",{"seekableDuration":2.96,"playableDuration":2.96,"currentTime":9.535}])
2022-07-14 22:13:38.481 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":7.961}])
2022-07-14 22:13:38.481 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoEnd",null])
2022-07-14 22:13:38.481 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoEnd",null])
2022-07-14 22:13:38.497 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":7.934}])
2022-07-14 22:13:38.497 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":6.409}])
2022-07-14 22:13:38.497 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([4897,"onVideoProgress",{"seekableDuration":2.96,"playableDuration":2.96,"currentTime":9.535}])
2022-07-14 22:13:38.497 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":7.798}])
2022-07-14 22:13:38.497 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([4897,"onVideoEnd",null])
2022-07-14 22:13:39.205 24490-28532/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:39.205 24490-28532/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 28200 free bytes and 27KB until OOM, target footprint 402653184, growth limit 402653184" (VmSize 50055296 kB)
2022-07-14 22:13:39.695 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([89,"onVideoEnd",null])
2022-07-14 22:13:40.407 24490-28550/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:40.407 24490-28550/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65552 byte allocation with 20984 free bytes and 20KB until OOM, target footprint 402653184, growth limit 402653184" (VmSize 50037820 kB)
2022-07-14 22:13:40.407 24490-28550/? E/LoadTask: OutOfMemory error loading stream
    java.lang.OutOfMemoryError: Failed to allocate a 65552 byte allocation with 20984 free bytes and 20KB until OOM, target footprint 402653184, growth limit 402653184
        at com.google.android.exoplayer2.upstream.DefaultAllocator.allocate(DefaultAllocator.java:102)
        at com.google.android.exoplayer2.source.SampleQueue.preAppend(SampleQueue.java:624)
        at com.google.android.exoplayer2.source.SampleQueue.sampleData(SampleQueue.java:544)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.readSample(Mp4Extractor.java:533)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.read(Mp4Extractor.java:187)
        at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:898)
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:381)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:929)
2022-07-14 22:13:41.107 24490-28573/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:41.107 24490-28573/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 5160 free bytes and 5160B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49915488 kB)
2022-07-14 22:13:41.143 24490-24490/? W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTEventEmitter.receiveEvent([3297,"onVideoProgress",{"seekableDuration":3,"playableDuration":3,"currentTime":6.703}])
2022-07-14 22:13:41.380 24490-28548/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:41.380 24490-28548/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 4792 free bytes and 4792B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49898000 kB)
2022-07-14 22:13:42.506 24490-28565/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:42.506 24490-28565/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 864 free bytes and 864B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49898000 kB)
2022-07-14 22:13:42.644 24490-28560/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:42.644 24490-28560/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 864 free bytes and 864B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49898000 kB)
2022-07-14 22:13:43.128 24490-28564/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:43.128 24490-28564/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 240 free bytes and 240B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49898000 kB)
2022-07-14 22:13:43.262 24490-28648/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:43.263 24490-28648/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 4016 byte allocation with 8 free bytes and 8B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49898000 kB)
2022-07-14 22:13:44.489 24490-28532/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:44.489 24490-28532/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65552 byte allocation with 40 free bytes and 40B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49880524 kB)
2022-07-14 22:13:44.925 24490-28536/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:44.926 24490-28536/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 232 free bytes and 232B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49880524 kB)
2022-07-14 22:13:45.062 24490-24544/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:45.062 24490-24544/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 56 byte allocation with 16 free bytes and 16B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49880524 kB)
2022-07-14 22:13:45.604 24490-28540/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:45.604 24490-28540/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 16 free bytes and 16B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49880524 kB)
2022-07-14 22:13:46.175 24490-28652/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:46.175 24490-28652/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 40 byte allocation with 16 free bytes and 16B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49880524 kB)
2022-07-14 22:13:46.392 24490-24758/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:46.392 24490-24758/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 48 byte allocation with 16 free bytes and 16B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49880524 kB)
2022-07-14 22:13:46.794 24490-28573/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:46.794 24490-28573/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65552 byte allocation with 16 free bytes and 16B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49880524 kB)
2022-07-14 22:13:47.650 24490-28442/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:47.651 24490-28442/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 152 byte allocation with 16 free bytes and 16B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49880524 kB)
2022-07-14 22:13:47.987 24490-24751/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:47.987 24490-24751/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 64 byte allocation with 16 free bytes and 16B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49880524 kB)
2022-07-14 22:13:48.804 24490-28557/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:48.804 24490-28557/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 0 free bytes and 0B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49880524 kB)
2022-07-14 22:13:49.100 24490-28538/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:49.100 24490-28538/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 32 byte allocation with 0 free bytes and 0B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49880524 kB)
2022-07-14 22:13:49.685 24490-24490/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:49.685 24490-24490/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 760 byte allocation with 400 free bytes and 400B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49845548 kB)
2022-07-14 22:13:49.825 24490-28548/? E/mypackage: [MemLeak.JavaTrack]: failed to write oom info: Operation not permitted
2022-07-14 22:13:49.825 24490-28548/? W/mypackage: Throwing OutOfMemoryError "Failed to allocate a 65552 byte allocation with 1824 free bytes and 1824B until OOM, target footprint 402653184, growth limit 402653184" (VmSize 49845548 kB)

Platform

Android Exoplayer

Environment info

React native info output:

System:
    OS: Windows 10 10.0.19043
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 5.93 GB / 23.88 GB
  Binaries:
    Node: 16.14.2 - C:\nodejs\node.EXE
    Yarn: 1.22.18 - C:\nodejs\yarn.CMD
    npm: 8.5.0 - C:\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK:
      API Levels: 28, 29, 30, 31
      Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.0, 30.0.2
      System Images: android-28 | Google Play Intel x86 Atom, android-29 | Google APIs Intel x86 Atom
      Android NDK: Not Found
    Windows SDK: Not Found
  IDEs:
    Android Studio: Not Found
    Visual Studio: 16.11.31911.196 (Visual Studio Community 2019)
  Languages:
    Java: javac 13 - C:\Program Files\Java\jdk-13\bin\javac.EXE
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2
    react-native: 0.68.2 => 0.68.2
    react-native-windows: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Library version: 4.4.5 ~ 5.2.0 ~ 6.0.0-alpha0 all have this problem

Steps To Reproduce

  1. Create a React Native project and install react-native-video
  2. Create a Video component in App, style it as absolute and stretch(or fixed), make it autoplay and silent and playInBackground and repeat and all of the possible way to make it like a background of App View and not bother any other players or applications outside. Prepare several videos with length 1~5s. (see the demo below)
  3. Create a state field in the App, and setInterval to update it regularly. This step is to let the Video component auto refresh many times.
  4. Run the application in an Android device. hold on and wait… until it crashes. …

demo:

import React from 'react';
import {Dimensions, View} from 'react-native';
import Video from 'react-native-video';

const videos = [require('./video1.mp4'), require('./video2.mp4')];
//// for production release
// const videos = [{uri:'raw/video1'}, {uri:'raw/video2'}]

export default function App() {
  const [src, setSrc] = React.useState(0);
  const [width, setWidth] = React.useState(Dimensions.get('window').width);
  const [height, setHeight] = React.useState(Dimensions.get('window').height);
  React.useEffect(() => {
    setTimeout(() => {
      setSrc((src + 1) % videos.length);
    }, 4000);
  }, [src]);

  return (
    <View
      style={{flex: 1}}
      onLayout={({nativeEvent}) => {
        setWidth(nativeEvent.layout.width);
        setHeight(nativeEvent.layout.height);
      }}>
      <Video
        source={videos[src]}
        style={[
          {
            position: 'absolute',
            top: 0,
            left: 0,
            zIndex: 1,
            width: width,
            height: height,
          },
        ]}
        resizeMode="cover"
        repeat
        allowsExternalPlayback={false}
        ignoreSilentSwitch="obey"
        mixWithOthers="mix"
        muted
        volume={0}
        selectedAudioTrack={{type: 'disabled'}}
        selectedTextTrack={{type: 'disabled'}}
        playWhenInactive
        playInBackground
        disableFocus
      />
    </View>
  );
}

Expected behaviour

  1. Not crash!

Suppose

the reactContext in the module has been catched in unsafe ways. When the context hot changed, the module could not run correctly, but it still had some kind of references to the old reactContext and some others, that makes memory leakages and errors.

About this issue

Most upvoted comments

I’ve been having the exact same issue for quite some time. If you alternate rendering a Video and another element such as an Image infinitely, the memory eventually runs out. I’ve seen it crash in as little as 45 minutes with a 1 second delay between each render. This is a problem for us since our app is for digital signage so we require the ability to render multiple media types in a list.

until there is a resolution on this, this solution(https://github.com/react-native-video/react-native-video/issues/2984) solved my case:

react-native: 0.72.3 react-native-video: 6.0.0-alpha.6 Android: 13 Videos <= 1min

<Video ref={playerRef} source={{ uri: file.path }} resizeMode=“contain” controls bufferConfig={{ minBufferMs: 2500, maxBufferMs: 3000, // default is 50 segundos, 3 seconds bufferForPlaybackMs: 2500, bufferForPlaybackAfterRebufferMs: 2500, }} />

@TensionCoding

I had a similar issue but for iOS, which isn’t related to ExoPlayer, and solved it this way.

You can use a custom view to wrap your video component, and use import { useIsFocused } from '@react-navigation/native'; To conditionally render the Video component only when the screen is focused, otherwise rendering an Image component instead. You can also pass in a flag to pre-load the Video if needed.

You can use Memo on other parts of the screen to further improve performance if needed.

Actually, I’ve tried from 4.4.5 to 6.0.0-alpha0, the problem alway exists.

@davinun99 I my mind all issues comes from exoplayer, not react native video itself. There is one leak issue in exoplayer, when you repeat small videos (with repeat=true) a workround is available in the thread. Some 4K video leaks. not 100% sure f the root cause. Keep in mind that video decoders of the device can also leak 😕

For me the repeat prop was causing the memory leak, fixed by repeating the video using ref

import Video, { VideoRef } from 'react-native-video';    

 <Video
          ref={videoRef}
          source={require('~/assets/videos/intro.mp4')}
          resizeMode="cover"
          repeat={false}
          onEnd={() => videoRef.current?.seek(0)}
        />

Hi Team,

We have this issue as well:

[ExoPlayer:Playback] Free memory reached 0, forcing garbage collection
Background concurrent mark compact GC freed 30863(9548KB) AllocSpace objects, 28(17MB) LOS objects, 39% free, 36MB/60MB, paused 1.693ms,7.307ms total 270.995ms
WaitForGcToComplete blocked Explicit on Background for 183.764ms
Explicit concurrent mark compact GC freed 3274(696KB) AllocSpace objects, 1(152KB) LOS objects, 40% free, 35MB/59MB, paused 2.520ms,7.236ms total 251.234ms
bufferpool2 0xb400006c2e7dde28 : 5(40960 size) total buffers - 4(32768 size) used buffers - 1433/1438 (recycle/alloc) - 5/1435 (fetch/transfer)

Made these changes with no improvement at all:

BufferConfig and repeat

android:largeHeap="true"
android:hardwareAccelerated="true"

Might be related to my work around here: https://github.com/react-native-video/react-native-video/issues/2984#issuecomment-1853228133

I have a FlatList w/ Videos and I was able to workaround this Memory issue by disabling repeat on Android:

<Video
        ref={vidRef}
        // RNV SOURCE IS HLS | .m3u8
        source={uri}
        ...

        // RNV ANDROID ISSUE - `hideShutterView` ONLY WORKS W/ TEXTURE VIEWS NOT SURFACE VIEWS :/
        useTextureView
        hideShutterView
        
        // RNV VIDEO LOOP (REPEAT) CAUSES MEMORY CRASH
        repeat={Platform.OS === 'android' ? false : true}
      />

Hello,

Have you tried bufferConfig ? Default max buffer length is 50 sec which is a lot.

I got my app crash with just 3 or 4 very short looping videos. After limiting the buffer to something shorter than video length the memory stabilized.

Source : https://stackoverflow.com/a/64900778/10859647

After running the app for about an hour using Exoplayer, I began getting out of memory errors. Here’s a sample of my logcat:

2022-09-14 22:57:51.884 426-23477/? I/MtkOmxVdecExV4L2: [0xa7118a00] -FlushOutputPort -> mNumPendingOutput(0)
2022-09-14 22:57:51.899 426-492/? I/MtkOmxVdecExV4L2: [0xa7118a00] MtkOmxVdec::FreeBuffer all output buffers have been freed!!! signal mOutPortFreeDoneSem(1)
2022-09-14 22:57:57.368 25405-23338/com.digitalsignageplayer W/alsignageplaye: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 17856 free bytes and 17KB until OOM, max allowed footprint 201326592, growth limit 201326592"
2022-09-14 22:57:57.861 23514-23542/? D/BlackbirdPluginHandler: kso device attributes: {"type":"DeviceAttributes","acceptLanguage":"en-US","apkVersion":"7.5.848.0","appVersion":"dynamic","cor":"US","deviceLocalTime":"America/Chicago","devicePartnerId":"NO_PARTNER_ID","deviceType":"AFTKA","directedId":"amzn1.account.AE3CHNEV5V52ASM2JEW3HVU22DRA","dsn":"G071R207132437JN","idfa":"03fb9eb9-3c8c-405a-976a-22eff9055cfe","launcherVersion":"639002610","optOut":false,"osVersion":"0024126400644","pconState":"0","pconViewingRestrictions":"-1","pfm":"ATVPDKIKX0DER","sha1UDID":"5f4806ce160a07799670accb9b000287302961d3","sisId":"A_riPLQ0gUegsXM-PsbbnD8","userAgent":"Dalvik/2.1.0 (Linux; U; Android 9; AFTKA Build/PS7292.2984N)"}
2022-09-14 22:57:57.988 23514-23542/? D/BlackbirdPluginHandler: kso device attributes: {"type":"DeviceAttributes","acceptLanguage":"en-US","apkVersion":"7.5.848.0","appVersion":"dynamic","cor":"US","deviceLocalTime":"America/Chicago","devicePartnerId":"NO_PARTNER_ID","deviceType":"AFTKA","directedId":"amzn1.account.AE3CHNEV5V52ASM2JEW3HVU22DRA","dsn":"G071R207132437JN","idfa":"03fb9eb9-3c8c-405a-976a-22eff9055cfe","launcherVersion":"639002610","optOut":false,"osVersion":"0024126400644","pconState":"0","pconViewingRestrictions":"-1","pfm":"ATVPDKIKX0DER","sha1UDID":"5f4806ce160a07799670accb9b000287302961d3","sisId":"A_riPLQ0gUegsXM-PsbbnD8","userAgent":"Dalvik/2.1.0 (Linux; U; Android 9; AFTKA Build/PS7292.2984N)"}
2022-09-14 22:58:01.855 25405-23338/com.digitalsignageplayer W/alsignageplaye: Throwing OutOfMemoryError "Failed to allocate a 65552 byte allocation with 13784 free bytes and 13KB until OOM, max allowed footprint 201326592, growth limit 201326592"
2022-09-14 22:58:03.672 25405-23338/com.digitalsignageplayer E/LoadTask: OutOfMemory error loading stream
      java.lang.OutOfMemoryError: Failed to allocate a 65552 byte allocation with 13784 free bytes and 13KB until OOM, max allowed footprint 201326592, growth limit 201326592
        at com.google.android.exoplayer2.upstream.DefaultAllocator.allocate(DefaultAllocator.java:102)
        at com.google.android.exoplayer2.source.SampleDataQueue.preAppend(SampleDataQueue.java:392)
        at com.google.android.exoplayer2.source.SampleDataQueue.sampleData(SampleDataQueue.java:181)
        at com.google.android.exoplayer2.source.SampleQueue.sampleData(SampleQueue.java:471)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.readSample(Mp4Extractor.java:552)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.read(Mp4Extractor.java:192)
        at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:982)
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:391)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
2022-09-14 22:58:07.705 426-492/? E/OMXNodeInstance: setParameter(0xa7118344:MTK.DECODER.AVC, OMX.google.android.index.allocateNativeHandle(0x7f20040e): Output:1 en=0) ERROR: BadParameter(0x80001005)
2022-09-14 22:58:07.705 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118340] --- GetOutputPortDefinition --- (176 144 176 160 5 46096 0x7f000001), pPortDef (176 144 176 160 5 46096 0x7f000001)
2022-09-14 22:58:07.707 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118340] --- GetOutputPortDefinition --- (3840 2160 3840 2176 5 12533776 0x7f000001), pPortDef (3840 2160 3840 2176 5 12533776 0x7f000001)
2022-09-14 22:58:07.824 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118340] --- GetOutputPortDefinition --- (3840 2160 3840 2176 5 12533776 0x7f000001), pPortDef (3840 2160 3840 2176 5 12533776 0x7f000001)
2022-09-14 22:58:07.824 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118340] --- GetOutputPortDefinition --- (3840 2160 3840 2176 5 12533776 0x7f000001), pPortDef (3840 2160 3840 2176 5 12533776 0x7f000001)
2022-09-14 22:58:08.107 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118340] --- GetOutputPortDefinition --- (3840 2160 3840 2176 5 12533776 0x7f000003), pPortDef (3840 2160 3840 2176 5 12533776 0x10f)
2022-09-14 22:58:08.114 426-24163/? I/MtkOmxVdecExV4L2: [0xa7118340] [getReconfigOutputPortSetting] u4CheckBufferCount: 13, u4ChagnedDPBSize: 5, mMinUndequeuedBufs: 4, FRAMEWORK_OVERHEAD: 3, MAX_COLORCONVERT_OUTPUTBUFFER_COUNT:1
2022-09-14 22:58:08.116 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118340] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x7f000003), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:08.117 426-24162/? I/MtkOmxVdecExV4L2: [0xa7118340] --- FTBQ: mNumPendingOutput 1; mFillThisBufQ.size() 1,  CCDst: 0, CCSrc: 0
2022-09-14 22:58:08.117 426-24162/? I/MtkOmxVdecExV4L2: [0xa7118340] -FlushOutputPort -> mNumPendingOutput(0)
2022-09-14 22:58:08.117 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118340] MtkOmxVdec::FreeBuffer all output buffers have been freed!!! signal mOutPortFreeDoneSem(1)
2022-09-14 22:58:08.120 426-24162/? I/MtkOmxVdecExV4L2: [0xa7118340] [getReconfigOutputPortSetting] u4CheckBufferCount: 13, u4ChagnedDPBSize: 5, mMinUndequeuedBufs: 4, FRAMEWORK_OVERHEAD: 3, MAX_COLORCONVERT_OUTPUTBUFFER_COUNT:1
2022-09-14 22:58:08.121 426-492/? I/MtkOmxVdecExV4L2: [0xa7118340] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x7f000003), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:08.121 426-26744/? I/MtkOmxVdecExV4L2: [0xa7118340] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x7f000003), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:09.926 426-28806/? I/MtkOmxVdecExV4L2: [0xa7118340] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x10f), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:09.982 455-484/? I/VCodecDrv: phHandle->fgOutputEarly 0
2022-09-14 22:58:09.983 426-24162/? I/MtkOmxVdecExV4L2: [0xa7118340] --- FTBQ: mNumPendingOutput 2; mFillThisBufQ.size() 0,  CCDst: 0, CCSrc: 0
2022-09-14 22:58:09.983 455-484/? I/VCodecDrv: phHandle->fgOutputEarly 0
2022-09-14 22:58:09.989 426-24162/? I/MtkOmxVdecExV4L2: [0xa7118340] -FlushOutputPort -> mNumPendingOutput(0)
2022-09-14 22:58:10.299 455-484/? I/VCodecDrv: phHandle->fgOutputEarly 0
2022-09-14 22:58:10.300 426-24162/? I/MtkOmxVdecExV4L2: [0xa7118340] --- FTBQ: mNumPendingOutput 9; mFillThisBufQ.size() 7,  CCDst: 0, CCSrc: 0
2022-09-14 22:58:10.300 455-484/? I/VCodecDrv: phHandle->fgOutputEarly 0
2022-09-14 22:58:10.301 426-24162/? I/MtkOmxVdecExV4L2: [0xa7118340] -FlushOutputPort -> mNumPendingOutput(0)
2022-09-14 22:58:10.334 426-28806/? I/MtkOmxVdecExV4L2: [0xa7118340] MtkOmxVdec::FreeBuffer all output buffers have been freed!!! signal mOutPortFreeDoneSem(1)
2022-09-14 22:58:18.193 24380-24429/? D/BlackbirdPluginHandler: kso device attributes: {"type":"DeviceAttributes","acceptLanguage":"en-US","apkVersion":"7.5.848.0","appVersion":"dynamic","cor":"US","deviceLocalTime":"America/Chicago","devicePartnerId":"NO_PARTNER_ID","deviceType":"AFTKA","directedId":"amzn1.account.AE3CHNEV5V52ASM2JEW3HVU22DRA","dsn":"G071R207132437JN","idfa":"03fb9eb9-3c8c-405a-976a-22eff9055cfe","launcherVersion":"639002610","optOut":false,"osVersion":"0024126400644","pconState":"0","pconViewingRestrictions":"-1","pfm":"ATVPDKIKX0DER","sha1UDID":"5f4806ce160a07799670accb9b000287302961d3","sisId":"A_riPLQ0gUegsXM-PsbbnD8","userAgent":"Dalvik/2.1.0 (Linux; U; Android 9; AFTKA Build/PS7292.2984N)"}
2022-09-14 22:58:18.201 24380-24429/? D/BlackbirdPluginHandler: kso device attributes: {"type":"DeviceAttributes","acceptLanguage":"en-US","apkVersion":"7.5.848.0","appVersion":"dynamic","cor":"US","deviceLocalTime":"America/Chicago","devicePartnerId":"NO_PARTNER_ID","deviceType":"AFTKA","directedId":"amzn1.account.AE3CHNEV5V52ASM2JEW3HVU22DRA","dsn":"G071R207132437JN","idfa":"03fb9eb9-3c8c-405a-976a-22eff9055cfe","launcherVersion":"639002610","optOut":false,"osVersion":"0024126400644","pconState":"0","pconViewingRestrictions":"-1","pfm":"ATVPDKIKX0DER","sha1UDID":"5f4806ce160a07799670accb9b000287302961d3","sisId":"A_riPLQ0gUegsXM-PsbbnD8","userAgent":"Dalvik/2.1.0 (Linux; U; Android 9; AFTKA Build/PS7292.2984N)"}
2022-09-14 22:58:19.964 25405-24374/com.digitalsignageplayer W/alsignageplaye: Throwing OutOfMemoryError "Failed to allocate a 65548 byte allocation with 53152 free bytes and 51KB until OOM, max allowed footprint 201326592, growth limit 201326592"
2022-09-14 22:58:23.995 25405-24374/com.digitalsignageplayer W/alsignageplaye: Throwing OutOfMemoryError "Failed to allocate a 65552 byte allocation with 53392 free bytes and 52KB until OOM, max allowed footprint 201326592, growth limit 201326592"
2022-09-14 22:58:24.067 25405-24374/com.digitalsignageplayer E/LoadTask: OutOfMemory error loading stream
      java.lang.OutOfMemoryError: Failed to allocate a 65552 byte allocation with 53392 free bytes and 52KB until OOM, max allowed footprint 201326592, growth limit 201326592
        at com.google.android.exoplayer2.upstream.DefaultAllocator.allocate(DefaultAllocator.java:102)
        at com.google.android.exoplayer2.source.SampleDataQueue.preAppend(SampleDataQueue.java:392)
        at com.google.android.exoplayer2.source.SampleDataQueue.sampleData(SampleDataQueue.java:181)
        at com.google.android.exoplayer2.source.SampleQueue.sampleData(SampleQueue.java:471)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.readSample(Mp4Extractor.java:552)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.read(Mp4Extractor.java:192)
        at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:982)
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:391)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
2022-09-14 22:58:24.913 426-28806/? E/OMXNodeInstance: setParameter(0xa7118544:MTK.DECODER.AVC, OMX.google.android.index.allocateNativeHandle(0x7f20040e): Output:1 en=0) ERROR: BadParameter(0x80001005)
2022-09-14 22:58:24.913 426-28806/? I/MtkOmxVdecExV4L2: [0xa7118540] --- GetOutputPortDefinition --- (176 144 176 160 5 46096 0x7f000001), pPortDef (176 144 176 160 5 46096 0x7f000001)
2022-09-14 22:58:24.915 426-28806/? I/MtkOmxVdecExV4L2: [0xa7118540] --- GetOutputPortDefinition --- (3840 2160 3840 2176 5 12533776 0x7f000001), pPortDef (3840 2160 3840 2176 5 12533776 0x7f000001)
2022-09-14 22:58:25.019 426-492/? I/MtkOmxVdecExV4L2: [0xa7118540] --- GetOutputPortDefinition --- (3840 2160 3840 2176 5 12533776 0x7f000001), pPortDef (3840 2160 3840 2176 5 12533776 0x7f000001)
2022-09-14 22:58:25.020 426-492/? I/MtkOmxVdecExV4L2: [0xa7118540] --- GetOutputPortDefinition --- (3840 2160 3840 2176 5 12533776 0x7f000001), pPortDef (3840 2160 3840 2176 5 12533776 0x7f000001)
2022-09-14 22:58:25.237 426-24827/? I/MtkOmxVdecExV4L2: [0xa7118540] [getReconfigOutputPortSetting] u4CheckBufferCount: 13, u4ChagnedDPBSize: 5, mMinUndequeuedBufs: 4, FRAMEWORK_OVERHEAD: 3, MAX_COLORCONVERT_OUTPUTBUFFER_COUNT:1
2022-09-14 22:58:25.239 426-492/? I/MtkOmxVdecExV4L2: [0xa7118540] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x7f000003), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:25.240 426-492/? I/MtkOmxVdecExV4L2: [0xa7118540] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x7f000003), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:25.241 426-24826/? I/MtkOmxVdecExV4L2: [0xa7118540] --- FTBQ: mNumPendingOutput 1; mFillThisBufQ.size() 1,  CCDst: 0, CCSrc: 0
2022-09-14 22:58:25.241 426-24826/? I/MtkOmxVdecExV4L2: [0xa7118540] -FlushOutputPort -> mNumPendingOutput(0)
2022-09-14 22:58:25.242 426-26744/? I/MtkOmxVdecExV4L2: [0xa7118540] MtkOmxVdec::FreeBuffer all output buffers have been freed!!! signal mOutPortFreeDoneSem(1)
2022-09-14 22:58:25.242 426-24826/? I/MtkOmxVdecExV4L2: [0xa7118540] [getReconfigOutputPortSetting] u4CheckBufferCount: 13, u4ChagnedDPBSize: 5, mMinUndequeuedBufs: 4, FRAMEWORK_OVERHEAD: 3, MAX_COLORCONVERT_OUTPUTBUFFER_COUNT:1
2022-09-14 22:58:25.243 426-26744/? I/MtkOmxVdecExV4L2: [0xa7118540] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x7f000003), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:25.243 426-26744/? I/MtkOmxVdecExV4L2: [0xa7118540] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x7f000003), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:25.303 426-26744/? I/MtkOmxVdecExV4L2: [0xa7118540] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x10f), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:25.321 25405-24373/com.digitalsignageplayer E/ExoPlayerImplInternal: Source error
      com.google.android.exoplayer2.upstream.Loader$UnexpectedLoaderException: Unexpected OutOfMemoryError: Failed to allocate a 65552 byte allocation with 53392 free bytes and 52KB until OOM, max allowed footprint 201326592, growth limit 201326592
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:421)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.lang.OutOfMemoryError: Failed to allocate a 65552 byte allocation with 53392 free bytes and 52KB until OOM, max allowed footprint 201326592, growth limit 201326592
        at com.google.android.exoplayer2.upstream.DefaultAllocator.allocate(DefaultAllocator.java:102)
        at com.google.android.exoplayer2.source.SampleDataQueue.preAppend(SampleDataQueue.java:392)
        at com.google.android.exoplayer2.source.SampleDataQueue.sampleData(SampleDataQueue.java:181)
        at com.google.android.exoplayer2.source.SampleQueue.sampleData(SampleQueue.java:471)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.readSample(Mp4Extractor.java:552)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.read(Mp4Extractor.java:192)
        at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:982)
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:391)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:764) 
2022-09-14 22:58:25.322 455-484/? I/VCodecDrv: phHandle->fgOutputEarly 0
2022-09-14 22:58:25.323 426-24826/? I/MtkOmxVdecExV4L2: [0xa7118540] --- FTBQ: mNumPendingOutput 2; mFillThisBufQ.size() 0,  CCDst: 0, CCSrc: 0
2022-09-14 22:58:25.323 455-484/? I/VCodecDrv: phHandle->fgOutputEarly 0
2022-09-14 22:58:25.325 426-24826/? I/MtkOmxVdecExV4L2: [0xa7118540] -FlushOutputPort -> mNumPendingOutput(0)
2022-09-14 22:58:25.688 455-484/? I/VCodecDrv: phHandle->fgOutputEarly 0
2022-09-14 22:58:25.689 426-24826/? I/MtkOmxVdecExV4L2: [0xa7118540] --- FTBQ: mNumPendingOutput 9; mFillThisBufQ.size() 8,  CCDst: 0, CCSrc: 0
2022-09-14 22:58:25.689 455-484/? I/VCodecDrv: phHandle->fgOutputEarly 0
2022-09-14 22:58:25.691 426-24826/? I/MtkOmxVdecExV4L2: [0xa7118540] -FlushOutputPort -> mNumPendingOutput(0)
2022-09-14 22:58:25.707 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118540] MtkOmxVdec::FreeBuffer all output buffers have been freed!!! signal mOutPortFreeDoneSem(1)
2022-09-14 22:58:28.814 426-29796/? E/OMXNodeInstance: setParameter(0xa7118d44:MTK.DECODER.AVC, OMX.google.android.index.allocateNativeHandle(0x7f20040e): Output:1 en=0) ERROR: BadParameter(0x80001005)
2022-09-14 22:58:28.815 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- GetOutputPortDefinition --- (176 144 176 160 5 46096 0x7f000001), pPortDef (176 144 176 160 5 46096 0x7f000001)
2022-09-14 22:58:28.818 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- GetOutputPortDefinition --- (3840 2160 3840 2176 5 12533776 0x7f000001), pPortDef (3840 2160 3840 2176 5 12533776 0x7f000001)
2022-09-14 22:58:28.879 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- GetOutputPortDefinition --- (3840 2160 3840 2176 5 12533776 0x7f000001), pPortDef (3840 2160 3840 2176 5 12533776 0x7f000001)
2022-09-14 22:58:28.879 426-29796/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- GetOutputPortDefinition --- (3840 2160 3840 2176 5 12533776 0x7f000001), pPortDef (3840 2160 3840 2176 5 12533776 0x7f000001)
2022-09-14 22:58:29.065 426-28806/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- GetOutputPortDefinition --- (3840 2160 3840 2176 5 12533776 0x7f000001), pPortDef (3840 2160 3840 2176 5 12533776 0x7f000001)
2022-09-14 22:58:29.066 426-24937/? I/MtkOmxVdecExV4L2: [0xa7118d40] [getReconfigOutputPortSetting] u4CheckBufferCount: 13, u4ChagnedDPBSize: 5, mMinUndequeuedBufs: 4, FRAMEWORK_OVERHEAD: 3, MAX_COLORCONVERT_OUTPUTBUFFER_COUNT:1
2022-09-14 22:58:29.069 455-484/? I/VCodecDrv: phHandle->fgOutputEarly 0
2022-09-14 22:58:29.070 426-24936/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- FTBQ: mNumPendingOutput 1; mFillThisBufQ.size() 1,  CCDst: 0, CCSrc: 0
2022-09-14 22:58:29.070 426-24936/? I/MtkOmxVdecExV4L2: [0xa7118d40] -FlushOutputPort -> mNumPendingOutput(0)
2022-09-14 22:58:29.075 426-28806/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x7f000003), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:29.076 426-28806/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x7f000003), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:29.077 426-24936/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- FTBQ: mNumPendingOutput 0; mFillThisBufQ.size() 0,  CCDst: 0, CCSrc: 0
2022-09-14 22:58:29.077 426-24936/? I/MtkOmxVdecExV4L2: [0xa7118d40] -FlushOutputPort -> mNumPendingOutput(0)
2022-09-14 22:58:29.077 426-28806/? I/MtkOmxVdecExV4L2: [0xa7118d40] MtkOmxVdec::FreeBuffer all output buffers have been freed!!! signal mOutPortFreeDoneSem(1)
2022-09-14 22:58:29.079 426-24936/? I/MtkOmxVdecExV4L2: [0xa7118d40] [getReconfigOutputPortSetting] u4CheckBufferCount: 13, u4ChagnedDPBSize: 5, mMinUndequeuedBufs: 4, FRAMEWORK_OVERHEAD: 3, MAX_COLORCONVERT_OUTPUTBUFFER_COUNT:1
2022-09-14 22:58:29.092 426-492/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x7f000003), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:29.092 426-28806/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- GetOutputPortDefinition --- (3840 2160 3840 2184 13 12583040 0x7f000003), pPortDef (3840 2160 3840 2184 13 12583040 0x10f)
2022-09-14 22:58:29.095 455-484/? I/VCodecDrv: phHandle->fgOutputEarly 0
2022-09-14 22:58:29.097 426-24936/? I/MtkOmxVdecExV4L2: [0xa7118d40] --- FTBQ: mNumPendingOutput 0; mFillThisBufQ.size() 0,  CCDst: 0, CCSrc: 0

The final memory error as my app crashed:

2022-09-14 23:01:38.166 25405-25264/com.digitalsignageplayer E/AndroidRuntime: FATAL EXCEPTION: Loader:ProgressiveMediaPeriod
    Process: com.digitalsignageplayer, PID: 25405
    java.lang.OutOfMemoryError: OutOfMemoryError thrown while trying to throw OutOfMemoryError; no stack trace available
2022-09-14 23:02:17.829 25405-25469/com.digitalsignageplayer W/alsignageplaye: Throwing OutOfMemoryError "Failed to allocate a 120 byte allocation with 80 free bytes and 80B until OOM, max allowed footprint 201326592, growth limit 201326592"
2022-09-14 23:02:21.407 25405-25417/com.digitalsignageplayer W/alsignageplaye: Throwing OutOfMemoryError "Failed to allocate a 56 byte allocation with 8 free bytes and 8B until OOM, max allowed footprint 201326592, growth limit 201326592"
2022-09-14 23:02:24.540 25405-25264/com.digitalsignageplayer W/alsignageplaye: Throwing OutOfMemoryError "Failed to allocate a 32 byte allocation with 8 free bytes and 8B until OOM, max allowed footprint 201326592, growth limit 201326592"
2022-09-14 23:02:31.327 25405-25405/com.digitalsignageplayer W/alsignageplaye: Throwing OutOfMemoryError "Failed to allocate a 16 byte allocation with 8 free bytes and 8B until OOM, max allowed footprint 201326592, growth limit 201326592"
2022-09-14 23:02:32.654 25405-25469/com.digitalsignageplayer W/alsignageplaye: Throwing OutOfMemoryError "Failed to allocate a 152 byte allocation with 8 free bytes and 8B until OOM, max allowed footprint 201326592, growth limit 201326592" (recursive case)
2022-09-14 23:02:35.385 25405-25417/com.digitalsignageplayer E/AndroidRuntime: FATAL EXCEPTION: FinalizerWatchdogDaemon
    Process: com.digitalsignageplayer, PID: 25405
    java.lang.OutOfMemoryError: Failed to allocate a 56 byte allocation with 8 free bytes and 8B until OOM, max allowed footprint 201326592, growth limit 201326592
        at dalvik.system.VMStack.getThreadStackTrace(Native Method)
        at java.lang.Thread.getStackTrace(Thread.java:1538)
        at java.lang.Thread.getAllStackTraces(Thread.java:1588)
        at com.bugsnag.android.ThreadState.<init>(ThreadState.kt:33)
        at com.bugsnag.android.ThreadState.<init>(ThreadState.kt:16)
        at com.bugsnag.android.ThreadState.<init>(ThreadState.kt:23)
        at com.bugsnag.android.EventInternal.<init>(EventInternal.kt:46)
        at com.bugsnag.android.Event.<init>(Event.java:35)
        at com.bugsnag.android.Client.notifyUnhandledException(Client.java:698)
        at com.bugsnag.android.ExceptionHandler.uncaughtException(ExceptionHandler.java:65)
        at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
        at java.lang.Thread.dispatchUncaughtException(Thread.java:1955)
        at java.lang.Daemons$FinalizerWatchdogDaemon.finalizerTimedOut(Daemons.java:436)
        at java.lang.Daemons$FinalizerWatchdogDaemon.runInternal(Daemons.java:283)
        at java.lang.Daemons$Daemon.run(Daemons.java:103)
        at java.lang.Thread.run(Thread.java:764)
2022-09-14 23:02:36.383 25405-25405/com.digitalsignageplayer A/alsignageplaye: java_vm_ext.cc:542] JNI DETECTED ERROR IN APPLICATION: JNI IsInstanceOf called with pending exception java.lang.OutOfMemoryError: Failed to allocate a 16 byte allocation with 8 free bytes and 8B until OOM, max allowed footprint 201326592, growth limit 201326592

And my profiler:

image image

image

I did receive one error around the same time as the memory errors occurred that seemed a bit weird to me. I’m not sure if this is related but for documentation purposes here it is:

2022-09-14 22:56:39.349 514-514/? W/Binder: Outgoing transactions from this process must be FLAG_ONEWAY
java.lang.Throwable
at android.os.BinderProxy.transact(Binder.java:1116)
at com.amazon.connectivitymanager.IControllerManager$Stub$Proxy.registerEventCallback(IControllerManager.java:439)
at com.amazon.connectivitymanager.ConnectivityManager.registerConnectivityEventCallback(ConnectivityManager.java:671)
at com.amazon.service.AmazonAutoPairService$2.onRemoteServiceConnected(AmazonAutoPairService.java:209)
at com.amazon.connectivitymanager.ConnectivityManager$1.onServiceConnected(ConnectivityManager.java:518)
at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1748)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1780)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:211)
at com.android.server.SystemServer.run(SystemServer.java:471)
at com.android.server.SystemServer.main(SystemServer.java:307)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:838)

Sample of my code: Each half-second, a component re-renders causing this code to evaluate. For the purposes of my test above, I rendered an image and then a video in an endless loop until the app crashed. It took about an hour. Under normal use, we see this error after a couple of days:

if (asset.content_type.includes('image/')) {
   return <Image testID='imageAsset' resizeMode={'stretch'} source={{uri:`file://...` }} style={styles.image} />
}

if (asset.content_type.includes('video/')) {
   return <Video repeat={false} resizeMode="cover" style={styles.video} fullScreen={true} source={{uri: `file:....` }} />
}