Repository: flutter
Issue: Off-screen CustomPaint widgets consume a lot of memory
Labels: framework,f: scrolling,customer: dream (g3),perf: memory,P3,team-framework,triaged-framework

## Details

1.  Please tell us exactly how to reproduce the problem you are running into, and how you measured the performance.

Instantiate a widget something like
```
SingleChildScrollWidget(
  child: List.generate(500, (_) => Container(
    height: 200,
    child: CustomPaint(
      painter: Sky(),
    ),
  ),
)
```
(Using `class Sky` from https://api.flutter.dev/flutter/rendering/CustomPainter-class.html which doesn't seem to have any reason to be memory-hungry.)

Observe the memory usage, either in observatory or in the fact that a low-memory device crashes.

Contrast
```
SingleChildScrollWidget(
  child: List.generate(500, (_) => Container(
    height: 200,
    decoration: BoxDecoration(shape: BoxShape.circle, color: Colors.red),
  ),
)
```

Whose memory usage is not nearly so dramatic.

The high memory usage and crash occurs in profile mode on a physical device. I'm not sure if we can switch to master channel in our environment though.

In the actual test case, the CustomPaint widgets were only about 80x80, and 300 of them caused memory usage to go up by around 100MB.

The same memory consumption occurs if the CustomPaint widgets are explicitly in an Offstage widget.

**Target Platform:** (not sure if I'm allowed to say)
**Target OS version/browser:** (not sure if I'm allowed to say)
**Devices:** (not sure if I'm allowed to say)

Flutter doctor output partially redacted:
```
[redacted]
[  +38 ms] [✓] Flutter (Channel google3, on Debian GNU/Linux rodete
5.10.40-1rodete1-amd64,
               locale en_US.UTF-8)
[   +7 ms]     • Framework revision bc1b91c4b3 (5 days ago),
2021-07-08T00:00:00.000
[   +4 ms]     • Engine revision c989ae17b7
[   +4 ms]     • Dart version e4125ef075
[redacted]
[  +31 ms] [✓] Android toolchain - develop for Android devices (Android SDK
version Stable)
[   +4 ms]     • Android SDK at google3
[   +4 ms]     • Platform Stable, build-tools Stable
[   +4 ms]     • Java binary at: /usr/local/buildtools/java/jdk/bin/java
[   +5 ms]     • Java version OpenJDK Runtime Environment (build
                 11.0.11+9-google-release-376318671)
[   +6 ms] [!] Android Studio (not installed)
[   +4 ms]     • Android Studio not found; download from
                 https://developer.android.com/studio/index.html
[   +4 ms]       (or visit
https://flutter.dev/docs/get-started/install/linux#android-setup
                 for detailed instructions).
[  +17 ms] List of devices attached
[   +8 ms] [✓] Connected device (1 available)
[   +4 ms]     • Linux (desktop) [redacted]
[   +5 ms] [✓] Google3 (on linux)
[   +3 ms]     • KVM enabled
[   +4 ms] ! Doctor found issues in 1 category.
[  +19 ms] "flutter doctor" took 554ms.
[+4333 ms] ensureAnalyticsSent: 4318ms
[  +22 ms] exiting with code 0
```

I realize "use a slivered scroller instead of a SingleChildScrollView" is an obvious workaround for *this specific oversimplified example*, but the real use-case needs to measure the heights of all the widgets (which can be impacted by word-wrap in their internal elements), which it seems you can't do without fully instantiating them.