react-native-video: IOS Memory Leak

Bug

Platform

Which player are you experiencing the problem on:

  • iOS

Environment info

Library version: 6.0.0-beta.0 Device: iPhone 14 Pro Max (Emulator)

Steps To Reproduce

  1. Show video component with an online video (in the example i am using the following 30mb sample video: https://sample-videos.com/video123/mp4/480/big_buck_bunny_480p_30mb.mp4)
  2. Unmount the video component
  3. Re-Mount the component
  4. The Memory usage of the app grows by about the size of the video in my case, and keeps growing with each repeat
  5. Profiling also seems to report several memory leaks, with most of the extra memory allocation going into VM: CoreMedia HTTP cache Screenshot 2023-12-04 at 19 25 17

Expected behaviour

  1. Video data is cleared from memory whenever the Video component is unmounted

Reproducible sample code

Full repo here: Clean RN init + RNVideo@6.0.0-beta.0 install only

import React, {useState} from 'react';
import {SafeAreaView, TouchableOpacity, Text, View} from 'react-native';
import Video from 'react-native-video';

function App() {
  const [hidden, setHidden] = useState(false);

  return (
    <SafeAreaView style={{flex: 1}}>
      <View style={{height: 300, width: '100%'}}>
        {!hidden && (
          <Video
            style={{height: 300, width: '100%'}}
            source={{
              uri: 'https://sample-videos.com/video123/mp4/480/big_buck_bunny_480p_30mb.mp4',
            }}
            controls
            paused={false}
          />
        )}
      </View>

      <TouchableOpacity
        style={{padding: 20, backgroundColor: hidden ? 'red' : 'green'}}
        onPress={() => setHidden(!hidden)}>
        <Text>Video: {hidden ? 'Unmounted' : 'Mounted'}</Text>
      </TouchableOpacity>
    </SafeAreaView>
  );
}

export default App;

Video sample

https://github.com/react-native-video/react-native-video/assets/20017227/beecff73-7bdf-4acf-a70e-c3d6ea49286a

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 13
  • Comments: 18

Most upvoted comments

Happening to me too. 😕 +1

Should be fixed with 6.0.0-beta.5, feel free to repo if it doesn’t

The same with FeedScreen using FlatList, try alpha 7 version work perfect, waiting for new update

Should be fixed with 6.0.0-beta.5, feel free to repo if it doesn’t

It works! Thanks a lot

Screenshot 2024-02-28 at 03 44 44