Skip to content

memory leak during repeated RiveView mount/unmount related to rive scripting #167

@edgarrii

Description

@edgarrii

Description

I’m observing what looks like a potential memory retention/leak pattern on iOS when a screen with RiveView is repeatedly mounted and unmounted. Also it's better to doublecheck on Android as well.

I cannot yet provide a full retain-chain proof, but profiling consistently shows that persistent Rive-related instances increase after repeated navigation cycles and do not return close to baseline.

Environment

  • @rive-app/react-native: 0.2.3
  • iOS Simulator (Apple Silicon)
  • React Native app with navigation (screen open/close flow)

Reproduction steps

  1. Render a screen that contains RiveView (file loaded via useRiveFile).
  2. Navigate to that screen and back.
  3. Repeat 20-50 times.
  4. Profile with Instruments -> Allocations and compare generations.

Observed behavior

Across repeated cycles, persistent instance counts for Rive-related classes increase, including:

  • RiveReactNativeView
  • HybridRiveView
  • HybridRiveFile
  • RiveRuntime.RiveView

This appears to indicate that some objects are retained longer than expected after unmount.

Expected behavior

After screen unmount (and short idle/GC period), Rive-related instances should be released and persistent counts should not keep increasing across cycles.

Minimal example

import { View, StyleSheet } from 'react-native';
import { RiveView, useRiveFile } from '@rive-app/react-native';

const FILE_INPUT = require('../assets/animation.riv');

export function RiveLeakTestScreen() {
  const { riveFile, isLoading, error } = useRiveFile(FILE_INPUT);

  if (!riveFile || isLoading || error) return null;

  return (
    <View style={styles.container}>
      <RiveView file={riveFile} style={styles.rive} autoPlay />
    </View>
  );
}

const styles = StyleSheet.create({
  container: { flex: 1 },
  rive: { width: '100%', height: '100%' },
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions