zhigang1992 / react-native-video-cache

Caching your video without headache
191 stars 59 forks source link

Too many open files #44

Closed mirceaciu closed 2 years ago

mirceaciu commented 3 years ago

I started using this with react-native-video. My video component receives the source as a prop, after a video is done playing the source is refreshed a playback starts again (loop play).

The files do get cached as the app is able to work offline an no more requests are made to the server. But after some time the app will crash with such an error

2021-10-13 22:22:21.938 12357-12357/com.zzz.player E/art: ashmem_create_region failed for 'indirect ref table': Too many open files
2021-10-13 22:22:21.938 12357-12357/com.zzz.player W/art: Throwing OutOfMemoryError "Could not allocate JNI Env"
2021-10-13 22:22:21.938 12357-12357/com.zzz.player D/AndroidRuntime: Shutting down VM
2021-10-13 22:22:21.939 12357-12357/com.zzz.player E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.zzz.player, PID: 12357
    java.lang.OutOfMemoryError: Could not allocate JNI Env
        at java.lang.Thread.nativeCreate(Native Method)
        at java.lang.Thread.start(Thread.java:730)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.<init>(ExoPlayerImplInternal.java:265)
        at com.google.android.exoplayer2.ExoPlayerImpl.<init>(ExoPlayerImpl.java:188)
        at com.google.android.exoplayer2.SimpleExoPlayer.<init>(SimpleExoPlayer.java:685)
        at com.google.android.exoplayer2.SimpleExoPlayer$Builder.build(SimpleExoPlayer.java:558)
        at com.brentvatne.exoplayer.ReactExoplayerView$6.run(ReactExoplayerView.java:417)
        at android.os.Handler.handleCallback(Handler.java:755)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6141)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)
2021-10-13 22:22:21.942 413-2352/system_process W/ActivityManager:   Force finishing activity com.zzz.player/.MainActivity

This will not happen if I just stream each video. With streaming I can run the app for days without issues but with caching after a few hours ( or minutes, random time) the app will crash.

mirceaciu commented 3 years ago

Could this be similar to the cached image issue described here https://github.com/facebook/react-native/issues/12220 ?

mirceaciu commented 2 years ago

I will close this as I assume the issue was on my side.

The way I wrote my code the Video component would never be released, so when the video source was changed a new component would be created but the old one kept open. This was a memory leak, possible case of 'to many files'