Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak when rendering a video in a loop #777

Open
c-moyer opened this issue Dec 9, 2022 · 0 comments
Open

Memory leak when rendering a video in a loop #777

c-moyer opened this issue Dec 9, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@c-moyer
Copy link

c-moyer commented Dec 9, 2022

Describe the bug
I'm here in hopes of salvaging our entire app due to a memory leak we experienced with react-native-video. We are having the same issue with expo-video-player as well. Our app is used for digital signage and plays videos and images in a loop based on a specified schedule. We will often play a quick 5 second video and then show an image, play another video, and another, etc. It all depends on what the user specifies for their content. We've noticed, however, after some portion of time we get OutOfMemory exceptions from ExoPlayer. In most cases it takes about a week, but when I alternate between a video and null once every 5 seconds, I can see the leak with expo-video-player within a few minutes. This ultimately causes our app to crash. I have noticed that the memory leak seems to occur when you unmount and remount the video component. In my screenshot below, you can see how the Native memory grew about 20MB within a 40 minute time period. This doesn't fair well for our app which is intended to run 24 hours per day. For this particular test, I'm using a manged Expo app. I created a development build with eas following the instructions here and installed the .apk on a virtual device that I have indicated below.

To Reproduce
Steps to reproduce the behavior:

  1. Run the following code:
import React, {Component} from 'react';
import {StyleSheet, View} from 'react-native';
import { Video } from 'expo-av';

const styles = StyleSheet.create({
  containerLight: {
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
    flexDirection: 'column',
    flex: 1,
  },
  video: {
    width: 400,
    height: 400,
  }
});

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      play: true,
    };
  }

  componentDidMount() {
    setInterval(() => {
      this.setState({play: !this.state.play})
    }, 5000)
  }

  render() {
    if(this.state.play === false){
      return null
    }

    return (
      <View style={ styles.containerLight}>
        <Video
          shouldPlay={true}
          style={styles.video}
          source={{
            uri: 'https://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4',
          }}
          useNativeControls
          resizeMode="contain"
          isLooping
        />
      </View>
    );
  }
}

export default App;

  1. Start Android Studio's memory profiler
  2. Allow the app to run for at least 30 minutes
  3. You will begin to see the memory growth via the profiler. This is the issue I am referring to that is crashing our application.

Link to reproduction on (Snack)[https://snack.expo.io/]

Expected behavior
A clear and concise description of what you expected to happen.
I expect the memory profiler to indicate that the application's memory usage is not growing over time.

Additional information:

  • Type:
    Emulator/Real Device
  • Device:
    Android TV (1080p) API 29 - Android 10.0 x86, Amazon Fire Stick 4k Max
  • OS:

image

![image](https://user-images.githubusercontent.com/7328278/206617261-c6fa5fb5-4ae4-4cdc-b1bc-98bd1a8a8a63.png)
  • Package version
    "expo-av": "~13.0.2",
  • Expo version (in app.json)
    "expo": "~47.0.8",
  • Expo CLI version
    "version": "0.4.10",

Additional context
None

Screenshots (if applicable)
Profiler after I ran a debuggable build on my Android TV emulator.
image

@c-moyer c-moyer added the bug Something isn't working label Dec 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant