mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
d2a6ff0c37
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/49125 Changelog: [internal] This adds support for taking JS memory heap snapshots from Fantom tests via `Fantom.saveJSMemoryHeapSnapshot`. This can be used in one-off tests to do memory analysis and determine the existence of leaks: ``` // Warm up Fantom.saveJSMemoryHeapSnapshot('/path/to/my/1.heapsnapshot'); // Do work Fantom.saveJSMemoryHeapSnapshot('/path/to/my/2.heapsnapshot'); // Clean up Fantom.saveJSMemoryHeapSnapshot('/path/to/my/3.heapsnapshot'); ``` Load these snapshots in Chrome and select "Objects allocated between 1 and 2" in the dropdown to see the potentially leaked objects. In the future we could introduce additional utilities to analyze the snapshots and do the detection automatically, e.g.: ``` // Warm up const baseline = Fantom.takeJSMemoryHeapSnapshot(); // Do work const before = Fantom.takeJSMemoryHeapSnapshot(); // Clean up const after = Fantom.takeJSMemoryHeapSnapshot(); const leaks = findMemoryLeaks(baseline, before, after); expect(leaks.sizeKB()).toBeLessThan(THRESHOLD); ``` Reviewed By: rshest Differential Revision: D68953788 fbshipit-source-id: 6b3899297837c582a7b7235909d59b3e1631913d