Skip to content

[0.77][Android] Memory Profiling not working, causing dev tools to disconnect #49158

Description

@Kartik4152

Description

Hi folks,
I've been trying to profile my apps memory usage using React Native DevTools but anytime I try to take a heap snapshot I get the following error:

An error occurred when a call to method 'buildSnapshot' was requested

TypeError: Cannot read properties of undefined (reading 'length')
    at b.initialize (http://127.0.0.1:8081/debugger-frontend/entrypoints/heap_snapshot_worker/heap_snapshot_worker.js:1:13359)
    at new b (http://127.0.0.1:8081/debugger-frontend/entrypoints/heap_snapshot_worker/heap_snapshot_worker.js:1:33684)
    at A.buildSnapshot (http://127.0.0.1:8081/debugger-frontend/entrypoints/heap_snapshot_worker/heap_snapshot_worker.js:1:43578)
    at HeapSnapshotWorkerDispatcher.dispatchMessage (http://127.0.0.1:8081/debugger-frontend/entrypoints/heap_snapshot_worker/heap_snapshot_worker.js:1:47247)

This issue is not isolated to my android device, other people on my team are facing the same issue using other android devices and even on emulator.

Steps to reproduce

  1. Create a new app using expo.
  2. Upgrade it to RN 0.77
  3. Connect a physical device using a wire.
  4. Run the app, open dev tools, go to memory tab and click on Take Snapshot
  5. Error

React Native Version

0.77.0

Output of npx react-native info

System:
  OS: macOS 14.5
  CPU: (8) arm64 Apple M1
  Memory: 63.67 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.20.4
    path: ~/.nvm/versions/node/v18.20.4/bin/node
  Yarn:
    version: 1.22.22
    path: ~/.nvm/versions/node/v18.20.4/bin/yarn
  npm:
    version: 10.7.0
    path: ~/.nvm/versions/node/v18.20.4/bin/npm
  Watchman:
    version: 2024.12.02.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK:
    Android NDK: 26.1.10909125
IDEs:
  Android Studio: 2024.1 AI-241.18034.62.2411.12071903
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.13
    path: /opt/homebrew/opt/openjdk@17/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.1.3
    wanted: ^15.1.3
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.77.0
    wanted: ~0.77.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Screenshots and Videos

Image
Screen.Recording.2025-02-04.at.3.13.00.PM.mov

Activity

  1. react-native-bot commented on Feb 4, 2025

    @react-native-bot
    Collaborator

    Warning

    Missing reproducer: We could not detect a reproducible example in your issue report. Please provide either:

  2. huntie commented on Feb 4, 2025

    @huntie
    Collaborator

    Hi @Kartik4152!

    • This looks valid, but I need more info / a reproducer. (Can you confirm this is an empty new Expo app, and what command was used to create?)
    • Ideally, I need the content of the failed Heap Snapshot in your app — this can be done by enabling the Protocol Monitor (link to a guide + how to download all messages).

    Pointer (for maintainers): Stack trace appears to be one of the .length reads in HeapSnapshot#initialize.

  3. changed the title [-]Memory Profiling not working, causing dev tools to disconnect[/-] [+][0.77][Android] Memory Profiling not working, causing dev tools to disconnect[/+] on Feb 4, 2025
  4. Nantris commented on Feb 19, 2025

    @Nantris

    Same exact issue on 0.76.x.

    This is not an empty Expo app in our case, but identical issue.

    Hermes with newArch.

  5. Kahore commented on Mar 5, 2025

    @Kahore

    plus 1 here, not an empty expo app

    getting "An error occurred when a call to method 'buildSnapshot' was requested"
    and

    TypeError: Cannot read properties of undefined (reading 'length')
       
       at b.initialize (http://127.0.0.1:8081/debugger-frontend/entrypoints/heap_snapshot_worker/heap_snapshot_worker.js:1:13359)
       at new b (http://127.0.0.1:8081/debugger-frontend/entrypoints/heap_snapshot_worker/heap_snapshot_worker.js:1:33684)
        at A.buildSnapshot (http://127.0.0.1:8081/debugger-frontend/entrypoints/heap_snapshot_worker/heap_snapshot_worker.js:1:43578)
        at HeapSnapshotWorkerDispatcher.dispatchMessage (http://127.0.0.1:8081/debugger-frontend/entrypoints/heap_snapshot_worker/heap_snapshot_worker.js:1:47247)
    

    in my case it's during first or second snapshot recording. Somewhere at stage "loading edges"
    The same goes for "Allocation ..."

  6. silasjmatson commented on Mar 7, 2025

    @silasjmatson

    I ran into the same issue on a relatively barebones ignite app using expo, hermes, and new arch (RN v0.76.7). I was able to reproduce with a bare expo app upgraded to RN 0.77.1, but I ran into other issues that may be confounding, so I didn't pursue that further.

    For what it's worth, here is the Protocol Monitor output (compressed to be small enough to upload here): ProtocolMonitor-20250307T101248.json.zip

  7. self-assigned this
    on Mar 11, 2025
  8. Rohit3523 commented on Mar 25, 2025

    @Rohit3523

    Getting the same error in version 0.76.7

  9. react-native-bot commented on Apr 19, 2025

    @react-native-bot
    Collaborator

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

  10. react-native-bot commented on Apr 19, 2025

    @react-native-bot
    Collaborator

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

  11. 27 remaining items

  12. added and removed
    Needs: ReproThis issue could be improved with a clear list of steps to reproduce the issue.
    on Oct 13, 2025
  13. vzaidman commented on Oct 13, 2025

    @vzaidman
    Contributor

    Fixed in react/react-native-devtools-frontend#211.

    This fix will be available in React Native 0.83. Unfortunately it will be too complicated to pick into older versions of React Native.

  14. vzaidman commented on Oct 13, 2025

    @vzaidman
    Contributor

    If you really want to apply the fix locally on older versions, edit the file
    node_modules/@react-native/debugger-frontend/dist/third-party/front_end/entrypoints/heap_snapshot_worker/heap_snapshot_worker.js

    from:

    async buildSnapshot(e){this.#me=this.#me||{}
    

    to:

    async buildSnapshot(e){await this.parsingComplete,this.#me=this.#me||{}
    

    as such:
    Image

  15. richardo2016x commented on Nov 24, 2025

    @richardo2016x

    Fixed in facebook/react-native-devtools-frontend#211.

    This fix will be available in React Native 0.83. Unfortunately it will be too complicated to pick into older versions of React Native.

    Thank you for the fix. However, fixing older versions should also be prioritized. As we all know, projects based on React Native don't easily upgrade latest minor versions (such as from 0.78 to 0.79) in a short period of time. This is because minor upgrades in React Native often bring about disruptive changes to the community ecosystem. Many projects cannot immediately upgrade to the latest 0.83. In fact, many popular third-party libraries in the React Native ecosystem cannot do so either.

  16. vzaidman commented on Nov 24, 2025

    @vzaidman
    Contributor

    Fixing older versions should also be prioritized.

    I totally get the inconvenience, but this is quite a lot of work for us, that we prefer to invest into making the latest versions better. If I choose to pick this, I'd need to actually pick the change into all these older versions, build, throughly test, and then release each of them separately. That process is pretty long.

    This does not fall within our pick requests policy. It's not a core feature, not a regression, and there's a workaround I described two comments above that would allow you to enable it using a patch on node_modules/@react-native/debugger-frontend, say using patch-package.

    Again- not ideal, but this is a matter of prioritization.

  17. richardo2016x commented on Nov 25, 2025

    @richardo2016x

    Fixing older versions should also be prioritized.

    I totally get the inconvenience, but this is quite a lot of work for us, that we prefer to invest into making the latest versions better. If I choose to pick this, I'd need to actually pick the change into all these older versions, build each, throughly test each, and then release it. That process is pretty long.

    This does not fall within our pick requests policy. It's not a core feature, not a regression, and there's a workaround I described two comments above that would allow you to enable it using a patch on node_modules/@react-native/debugger-frontend, say using patch-package.

    Again- not ideal, but this is a matter of prioritization.

    I understand the heavy workload you're undertaking, and I hope to avoid adding any extra burden. I'd be willing to patch it if possible (in fact, I've already tried, but it didn't work). However, the workaround you provided seems to only work for the more demanding version. I'm currently using RN 0.77, and the code structure in its corresponding node_modules/@react-native/debugger-frontend package is slightly different from the patch results you provided. For example, in version 0.77, buildSnapshot is not an asynchronous function, and the entire file lacks a callable this parsingComplete function. Furthermore, in 0.77, the code snippet for buildSnapshot is this.#he=this.#he||{} instead of this.#me=this.#me||{}.

    If convenient, I would also appreciate a patch for 0.77.

  18. vzaidman commented on Nov 25, 2025

    @vzaidman
    Contributor

    the code structure in its corresponding node_modules/@react-native/debugger-frontend package is slightly different

    This is yet another reason not to fix it in older versions- the fix might be different, so it will be demanding more time, and more testing before releasing.

    I did look at the code. The patch in that version should also include adding:

    this.parsingComplete = this.#ge()
    

    to the constructor where this.#ge() is called.

  19. camchis commented on Dec 3, 2025

    @camchis

    the code structure in its corresponding node_modules/@react-native/debugger-frontend package is slightly different

    This is yet another reason not to fix it in older versions- the fix might be different, so it will be demanding more time, and more testing before releasing.

    I did look at the code. The patch in that version should also include adding:

    this.parsingComplete = this.#ge()
    

    to the constructor where this.#ge() is called.

    This made no difference for me on 0.77.3 - I assume buildSnapshot() not being async is probably causing an issue as well

  20. richardo2016x commented on Dec 6, 2025

    @richardo2016x

    the code structure in its corresponding node_modules/@react-native/debugger-frontend package is slightly different

    This is yet another reason not to fix it in older versions- the fix might be different, so it will be demanding more time, and more testing before releasing.

    I did look at the code. The patch in that version should also include adding:

    this.parsingComplete = this.#ge()
    

    to the constructor where this.#ge() is called.

    This patch is ineffective. I located the issue by setting breakpoints, and the error in the debugger's JavaScript code isn't actually caused by a problem within this function. Instead, it stems from a mismatch between the format of the reported data and the debugger's JavaScript's internal expectations. The debugger's JavaScript is attempting to access the first element of an empty array (i.e., the list's value is [], but the program is trying to access list[0][0]). You can almost always reproduce this problem when using react-native 0.77.3, opening its accompanying devtools, and attempting to record a heap snapshot.

    Of course, based on your team's previous replies, I understand that you won't spend time reproducing this problem (let alone fixing it). Therefore, you relied on your imagination, slightly modifying a patch applicable to 0.82.x, and used it to reply to us. I think this is inappropriate, but we have no way to address it.

    In the near future, we might try to debug the @react-native/debugger-frontend corresponding to react-native 0.77.3 ourselves and fix it.

  21. SemihGk commented on Feb 18, 2026

    @SemihGk

    I also encountered the same issue. Yes, upgrading to newer versions is very troublesome for complex projects. For those, there is an alternative approach. Hermes engine exposes a method to take a heap snapshot: https://github.com/facebook/hermes/blob/static_h/doc/MemoryProfilers.md#taking-a-heap-snapshot-from-c

    On my side, I created a method that subscribes a key event and this method generates a temp file. Then, invoke the key event such as adb shell input keyevent 129 which would eventually call Hermes method via fb jsi runtime..

    #include <jsi/instrumentation.h>
    
    // invoke the method on js thread like (invoker->invokeAsync).
    rt.instrumentation().createSnapshotToFile("/tmp/filename.heapsnapshot");
    

    eventually download the file from Android Studio device explorer. Since you do not need to run dev tools, collecting heap snapshot is even more accurate. Unfortunately, you can run this method on debug mode only. It is not supported for release version Hermes engine.

  22. Tushar200018 commented on Jun 9, 2026

    @Tushar200018

    The patch you provided is not working for react-native : 0.79.6. Can you please provide the correct patch for this?

  23. vzaidman commented on Jun 9, 2026

    @vzaidman
    Contributor

    The patch you provided is not working for react-native : 0.79.6. Can you please provide the correct patch for this?

    The fix for these versions seems to be totally different.

    Since it's very time consuming to even prepare a working environment for such an old version to find the fix, the team will not be doing that.

    Consider @SemihGk's workaround one comment above, or maybe somehow involve AI to find a patch based on the fix for version 0.83.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugDebuggingIssues related to React Native DevTools or legacy JavaScript/Hermes debuggingImpact: CrashNever gets stalePrevent those issues and PRs from getting stale

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions