react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Memory usage is constantly increasing due to useState used in SetInterval

Open Merthasan0 opened this issue 1 year ago • 4 comments

Description

I set up a timer that will run every x seconds, which is added to the UseEffect content. Inside, I update my useState element, which will be updated every x seconds.

Although the process is not very large, memory usage increases by 1 MB starting from 72 MB per second, and after about 10 hours, the application closes because the memory limit is exceeded (around 2 GB).

When the setData command is removed, memory usage remains at a constant 72 MB.

const [getData, setData] = useState(0);

useEffect(() => { const interval = setInterval(() => { setData(prevData => prevData + 1); }, 1000); return () => { clearInterval(interval); }; }, []);

For example, when I set a constantly constant variable

setData(1);

memory progresses steadily.

However, as an example to change the data inside

setData(prevData => prevData + 1);

OR

let test = Math.random(); setList_GPDSV_Devices(test);

When I replace the data in it with different data, the memory starts to increase.

Steps to reproduce

yarn ios and the memory use started to increase.

React Native Version

0.70.6

Affected Platforms

Runtime - iOS

Output of npx react-native info

System:
    OS: macOS 13.0.1
    CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
    Memory: 2.62 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 14.21.2 - ~/.volta/tools/image/node/14.21.2/bin/node
    Yarn: 1.22.19 - ~/.volta/tools/image/yarn/3.2.4/bin/yarn
    npm: 9.8.1 - ~/.volta/tools/image/npm/9.8.1/bin/npm
    Watchman: 2023.10.09.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.14.2 - /Users/mertcelik/.rvm/gems/ruby-2.7.5/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1
    Android SDK: Not Found
  IDEs:
    Android Studio: 2022.1 AI-221.6008.13.2211.9514443
    Xcode: 14.1/14B47b - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.15.1 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.1.0 => 18.1.0 
    react-native: 0.70.6 => 0.70.6 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Stacktrace or Logs

.

Reproducer

.

Screenshots and Videos

No response

Merthasan0 avatar Feb 29 '24 10:02 Merthasan0

:warning: Unsupported Version of React Native
:information_source: It looks like your issue or the example you provided uses an unsupported version of React Native.

Due to the number of issues we receive, we're currently only accepting new issues against one of the supported versions. Please upgrade to latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If you cannot upgrade, please open your issue on StackOverflow to get further community support.

github-actions[bot] avatar Feb 29 '24 10:02 github-actions[bot]

:warning: Missing Reproducible Example
:information_source: We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.

github-actions[bot] avatar Feb 29 '24 10:02 github-actions[bot]

Please add a repro with the latest version with active support.

You can see the supported versions here

migueldaipre avatar Feb 29 '24 11:02 migueldaipre

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

github-actions[bot] avatar Apr 03 '24 05:04 github-actions[bot]

This issue was closed because the author hasn't provided the requested feedback after 7 days.

github-actions[bot] avatar Apr 10 '24 05:04 github-actions[bot]