Skip to content

Flutter framework is leaking in debug mode for gallery app. #107338

Description

@polina-c

Steps to repro:

  1. Follow go/dart-leak-tracking to leak-track gallery on macos
  2. Update main.dart in Gallery to include flutter objects: startAppLeakTracking(enabledFamilies: {'flutterRendering'});
  3. Start gallery in debug mode
  4. Go to crane screen 'Crane ' and make the window smaller so that flights are shown as list, not as squares
  5. Scroll the list and notice about 3000 not GCed leaks in console
  6. Connect with DevTools, open Memory > Leaks, and click 'Analyze and Download'
  7. Find information like this in YAML: https://drive.google.com/file/d/1DJt5_pZRDZCSJ2CkThbgyC8j6T9ypFI1/view?usp=sharing

If you remove WeakRef from DebugCreator (the WeakRef is here just in the flutter branch for the leak tracker), you will get the leaks earlier, on main screen of gallery, by resizing and scrolling:
https://github.com/polina-c/flutter/blob/0b01eaaf89ddde670fb5494d49be059f172c8c70/packages/flutter/lib/src/widgets/framework.dart#L6394

Commenting out this line does not fix the issue:

child._layerHandle.layer!.debugCreator = child.debugCreator ?? child;

Activity

  1. polina-c commented on Jul 9, 2022

    @polina-c
    ContributorAuthor

    Why it is important to fix:

    1. We want the leak detector tool to be valuable in both debug and profile mode
    2. We want debug memory footprint to be close to release one
  2. maheshj01 commented on Jul 11, 2022

    @maheshj01
    Member

    Hi @polina-c, Thanks for filing the issue. Labeling the issue for further investigation from the team.

  3. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    c: performanceRelates to speed or footprint issues (see "perf:" labels)
    perf: memoryPerformance issues related to memory
    platform-macosBuilding on or for macOS specifically
    and removed
    in triagePresently being triaged by the triage team
    on Jul 11, 2022
  4. dkwingsmt commented on Jul 11, 2022

    @dkwingsmt
    Contributor

    The file in the Google Drive seems private to me. Can you make sure it is publicly accessible?

  5. polina-c commented on Jul 11, 2022

    @polina-c
    ContributorAuthor

    The file in the Google Drive seems private to me. Can you make sure it is publicly accessible?

    Fixed. Let me know if something is still wrong.

  6. dkwingsmt commented on Jul 11, 2022

    @dkwingsmt
    Contributor

    The leaking state seems to be EditableTextState. @LongCatIsLooong Can you take a look?
    Also in a scroll view. cc @Piinks

  7. jason-simmons commented on Jul 12, 2022

    @jason-simmons
    Member

    So far I've been unable to reproduce this.

    I tried running the https://github.com/polina-c/flutter/tree/leak-tracking2 branch of the framework with a compatible version of Gallery (flutter-team-archive/gallery@1dfcd61)

    I then added this to main():

      WidgetsFlutterBinding.ensureInitialized();
      startAppLeakTracking(
          enabledFamilies: {'flutterRendering'},
          );
    

    Next I started Gallery, went to the Crane screen, resized the window, and scrolled through the list. Initially I did not get any reports of leaks.

    However, after a few more seconds of scrolling I got a native code crash in the Dart runtime (apparently related to a stack overflow):

    ../../third_party/dart/runtime/vm/object_service.cc: 1738: error: unreachable code
    version=2.17.0 (stable) (Mon May 9 10:36:47 2022 +0200) on "macos_x64"
    pid=78442, thread=27651, isolate_group=main(0x7f81f2812800), isolate=main(0x7f81f0829000)
    isolate_instructions=114cca540, vm_instructions=114cca540
      pc 0x0000000114e28c15 fp 0x00007000029320b0 dart::Profiler::DumpStackTrace(void*)+0x85
      pc 0x0000000114cca754 fp 0x0000700002932190 dart::Assert::Fail(char const*, ...) const+0x84
      pc 0x0000000114e20f7c fp 0x00007000029321b0 dart::FinalizerEntry::PrintJSONImpl(dart::JSONStream*, bool) const+0x2c
      pc 0x0000000114d20e95 fp 0x0000700002932260 dart::ActivationFrame::PrintToJSONObjectRegular(dart::JSONObject*)+0x375
      pc 0x0000000114ea117d fp 0x00007000029322b0 dart::ServiceEvent::PrintJSON(dart::JSONStream*) const+0x3cd
      pc 0x0000000114d46101 fp 0x0000700002932420 dart::Isolate::PrintJSON(dart::JSONStream*, bool)+0x5f1
      pc 0x0000000114e8908e fp 0x0000700002932570 dart::Service::InvokeMethod(dart::Isolate*, dart::Array const&, bool)+0x32e
      pc 0x0000000114e896c3 fp 0x00007000029325a0 dart::Service::HandleIsolateMessage(dart::Isolate*, dart::Array const&)+0x23
      pc 0x0000000114d41223 fp 0x0000700002932680 dart::IsolateMessageHandler::HandleMessage(std::__1::unique_ptr<dart::Message, std::__1::default_delete<dart::Message> >)+0x283
      pc 0x0000000114d70453 fp 0x0000700002932700 dart::MessageHandler::HandleMessages(dart::MonitorLocker*, bool, bool)+0x133
      pc 0x0000000114d70874 fp 0x0000700002932740 dart::MessageHandler::HandleOOBMessages()+0x54
      pc 0x0000000114eb6428 fp 0x0000700002932780 dart::Thread::HandleInterrupts()+0x108
      pc 0x0000000114e7fba4 fp 0x0000700002932950 dart::DRT_StackOverflow(dart::NativeArguments)+0x7a4
      pc 0x00000001221825c3 fp 0x0000700002932998 Unknown symbol
    

    I also tried checking the Dart Observatory allocation profile while scrolling through Crane with the leak detector disabled. But I did not notice anything unusual.

  8. polina-c commented on Jul 12, 2022

    @polina-c
    ContributorAuthor

    @jason-simmons , thanks for checking. Yes, crash happens sometimes for me. But other times I see leaks. Can we have GVC session? I sent you invite.

  9. polina-c commented on Jul 12, 2022

    @polina-c
    ContributorAuthor

    Had discussion with Jason. Discoveries are:

    1. Gallery crashes for Jason every time, while it crashes for me ~5% of times. Most likely it is because my mac is newer.
    2. We found discrepancy between heap snapshot and observatory: while the snapshot contains the leaking object _RenderEditableCustomPaint, observatory shows there is no instances.
  10. added
    P2Important issues not at the top of the work list
    on Jul 14, 2022
  11. polina-c commented on Jul 20, 2022

    @polina-c
    ContributorAuthor

    Merged https://github.com/polina-c/flutter/tree/leak-tracking2 with flutter muster to make troubleshooting easier.

  12. polina-c commented on Jul 24, 2022

    @polina-c
    ContributorAuthor

    I tested it with Flutter 3.0.1-0.0.pre.1889 and could not repro both crash and leaks.
    Closing.

  13. github-actions commented on Aug 9, 2022

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  14. locked as resolved and limited conversation to collaborators on Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: desktopRunning on desktopc: performanceRelates to speed or footprint issues (see "perf:" labels)frameworkflutter/packages/flutter repository. See also f: labels.perf: memoryPerformance issues related to memoryplatform-macosBuilding on or for macOS specificallyr: solvedIssue is closed as solved

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions