From 4ee326f52c5f27c8a347dca9c50d12eb54e31bec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Tue, 12 Aug 2025 11:08:08 -0700 Subject: [PATCH] Add documentation for JS memory profiler in Fantom (#53226) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53226 Changelog: [internal] This adds documentation about how to take JS memory heap snapshots in Fantom. Reviewed By: lenaic Differential Revision: D80090283 fbshipit-source-id: 04f66a62aa756d1020b8d8ef6fc0ea7e68341710 --- .../react-native-fantom/__docs__/README.md | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/private/react-native-fantom/__docs__/README.md b/private/react-native-fantom/__docs__/README.md index 055bf42b0ff..60e9c90b243 100644 --- a/private/react-native-fantom/__docs__/README.md +++ b/private/react-native-fantom/__docs__/README.md @@ -244,6 +244,44 @@ trace will be created for each variant. You can analyze the traces loading them in Chrome DevTools directly. You can also open them in VS Code, which provides a built-in extension for analysis. +#### JS memory profiler + +You can manually take JS memory heap snapshots during test execution using +`Fantom.takeJSMemoryHeapSnapshot()`. E.g.: + +```javascript +// Using the 3 snapshot method to detect memory leaks: + +// Warm up +renderView(); +destroyView(); + +// #1 +Fantom.takeJSMemoryHeapSnapshot(); + +renderView(); + +// #2 +Fantom.takeJSMemoryHeapSnapshot(); + +destroyView(); + +// #3 +Fantom.takeJSMemoryHeapSnapshot(); + +// See the objects allocated between #1 and #2 that still exist in #3. +``` + +This function will force a garbage collection pass, take a snapshot of the JS +memory heap and print a message indicating where it was saved. E.g.: + +```text +💾 JS heap snapshot saved to /path/to/react-native/private/react-native-fantom/.out/js-heap-snapshots/View-itest.js-2025-08-12T14:29:25.987Z.heapsnapshot +``` + +You can have multiple calls to `Fantom.takeJSMemoryHeapSnapshot()` in your test, +and each one will create a different file. + ### FAQ #### How is this different from Jest tests?