Repository: flutter
Issue: [google_maps_flutter] [iOS] Memory limit exceeded
Labels: platform-ios,p: maps,package,has reproducible steps,P2,c: fatal crash,team-ios,triaged-ios,found in release: 3.22,found in release: 3.23

### Steps to reproduce

1. flutter create .
2. flutter pub add google_maps_flutter
3. pass through installation guide in readme
4. create GoogleMap widget with a single dashed polyline and specific coordinates 
5. Test on real iOS device (`iPhone 8, arm64, 16.7.8` in my case)

### Expected results

Polylines should be rendered fast and without any memory issues on any amount/distance between points

### Actual results

Crash with error `Thread 1: EXC_RESOURCE (RESOURCE_TYPE_MEMORY: high watermark memory limit exceeded) (limit=1450 MB)` 
or `The app "Runner" has been killed by the operating system because it is using too much memory.`
<img width="457" alt="Снимок экрана 2024-06-26 в 05 42 09" src="https://github.com/flutter/flutter/assets/20296963/c3033e3a-eb88-42c7-bb99-7186516e8312">


### Code sample

<details open><summary>Code sample</summary>

[Repository](https://github.com/Exnonull/google_maps_bug)

```dart
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;
  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    Set<Polyline> polylines = {
      Polyline(
        color: Colors.black,
        polylineId: PolylineId(
          'global',
        ),
        width: 5,
        patterns: [
          PatternItem.dot,
          PatternItem.gap(10), // without gap it's doesn't crash...
        ],
        points: [
          LatLng(50.450952, 30.522617),
          LatLng(37.33492222, -122.03304215),
        ],
      )
    };
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: GoogleMap(
        polylines: polylines,
        initialCameraPosition: CameraPosition(
          target: LatLng(0, 0),
          zoom: 0.0,
        ),
      ),
    );
  }
}

```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

Crashes instantly on real device.
<img width="457" alt="Снимок экрана 2024-06-26 в 05 42 09" src="https://github.com/flutter/flutter/assets/20296963/a402c786-7b6f-4f36-868e-f5906229e8f7">


</details>


### Logs

<details open><summary>Logs</summary>

`flutter run --verbose`

```console
[+2572 ms] Process 1812 stopped
[   +4 ms] * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_RESOURCE (RESOURCE_TYPE_MEMORY: high watermark memory limit exceeded) (limit=1450 MB)
[        ]     frame #0: 0x0000000102c836c4 Runner`std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::basic_string<std::nullptr_t>(char
const*) + 56
[   +1 ms] Runner`std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::basic_string<std::nullptr_t>:
[        ] ->  0x102c836c4 <+56>: strb   w20, [x19, #0x17]
[        ]     0x102c836c8 <+60>: mov    x22, x19
[        ]     0x102c836cc <+64>: cbnz   x20, 0x102c836f4          ; <+104>
[        ]     0x102c836d0 <+68>: b      0x102c83704               ; <+120>
[        ] Target 0: (Runner) stopped.
[        ] thread backtrace all
[        ] process detach
[ +660 ms] Process 1812 exited with status = 9 (0x00000009) Terminated due to memory issue
[   +2 ms] warning: could not execute support code to read Objective-C class data in the process. This may reduce the quality of type information available.
[  +12 ms] ios-deploy exited with code 0
[   +2 ms] Service protocol connection closed.
[        ] Lost connection to device.
[   +1 ms] DevFS: Deleting filesystem on the device
(file:///private/var/mobile/Containers/Data/Application/FFAC2961-B681-4FBE-B91D-2EC2C21A77D5/tmp/google_maps_bugRq3tOp/google_maps_bug/)
[ +254 ms] Ignored error while cleaning up DevFS: TimeoutException after 0:00:00.250000: Future not completed

[   +5 ms] "flutter run" took 94 998ms.
[  +52 ms] ensureAnalyticsSent: 45ms
[        ] Running 1 shutdown hook
[  +10 ms] Shutdown hooks complete
[        ] exiting with code 0
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.22.2, on macOS 14.1 23B74 darwin-x64, locale ru-RU)
    • Flutter version 3.22.2 on channel stable at /Users/random/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 761747bfc5 (3 weeks ago), 2024-06-05 22:15:13 +0200
    • Engine revision edd8546116
    • Dart version 3.4.3
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/random/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Users/random/Desktop/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A507
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Users/random/Desktop/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] Connected device (3 available)
    • iPhone (random) (mobile) • 1a76dc0fbf5fe4481ccbd4811ec5bb5bfa654635 • ios            • iOS 16.7.8 20H343
    • macOS (desktop)          • macos                                    • darwin-x64     • macOS 14.1 23B74 darwin-x64
    • Chrome (web)             • chrome                                   • web-javascript • Google Chrome 126.0.6478.116

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>