Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
polina-c opened this issue Jul 9, 2022 · 11 comments
Closed

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

polina-c opened this issue Jul 9, 2022 · 11 comments
Labels
a: desktop Running on desktop c: performance Relates to speed or footprint issues (see "perf:" labels) framework flutter/packages/flutter repository. See also f: labels. P2 Important issues not at the top of the work list perf: memory Performance issues related to memory platform-mac Building on or for macOS specifically r: solved Issue is closed as solved

Comments

@polina-c
Copy link
Contributor

polina-c commented Jul 9, 2022

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;

@polina-c
Copy link
Contributor Author

polina-c commented Jul 9, 2022

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

@maheshj01
Copy link
Member

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

@maheshj01 maheshj01 added framework flutter/packages/flutter repository. See also f: labels. c: performance Relates to speed or footprint issues (see "perf:" labels) perf: memory Performance issues related to memory platform-mac Building on or for macOS specifically a: desktop Running on desktop and removed in triage Presently being triaged by the triage team labels Jul 11, 2022
@dkwingsmt
Copy link
Contributor

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

@polina-c
Copy link
Contributor Author

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.

@dkwingsmt
Copy link
Contributor

dkwingsmt commented Jul 11, 2022

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

@jason-simmons
Copy link
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/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.

@polina-c
Copy link
Contributor Author

@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.

@polina-c
Copy link
Contributor Author

polina-c commented Jul 12, 2022

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.

@gspencergoog gspencergoog added the P2 Important issues not at the top of the work list label Jul 14, 2022
@polina-c
Copy link
Contributor Author

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

@polina-c
Copy link
Contributor Author

polina-c commented Jul 24, 2022

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

@maheshj01 maheshj01 added the r: solved Issue is closed as solved label Jul 26, 2022
@github-actions
Copy link

github-actions bot commented Aug 9, 2022

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: desktop Running on desktop c: performance Relates to speed or footprint issues (see "perf:" labels) framework flutter/packages/flutter repository. See also f: labels. P2 Important issues not at the top of the work list perf: memory Performance issues related to memory platform-mac Building on or for macOS specifically r: solved Issue is closed as solved
Projects
None yet
Development

No branches or pull requests

5 participants