rrousselGit / freezed

Code generation for immutable classes that has a simple syntax/API without compromising on the features.
https://pub.dev/packages/freezed
1.94k stars 237 forks source link

Dart consumes excessive RAM when part directive is missing in freezed-generated code #1117

Open AntoniPochopien opened 3 months ago

AntoniPochopien commented 3 months ago

Description When using the freezed package in Flutter, if the part directive is not annotated with the .freezed.dart file name, Dart starts consuming a significant amount of RAM. The memory usage keeps increasing with each passing second. The freezed process in the console becomes unresponsive, and even after stopping the file generation process, Dart continues to consume more RAM. The only way to stop this is by manually killing the Dart process.

Note I want to note that this is not a critical bug, since it comes from developer wrong usage of the package, but I think that this scenario should be handled somehow to prevent such resource consumption issues.

To Reproduce

  1. Create a new Flutter project.
  2. Add the freezed package to pubspec.yaml.
  3. Create a Dart file with a freezed class but forget to add the part directive with the .freezed file name. eg. part 'x.dart';
  4. Run the build runner to generate the code.

Expected behavior An error should be thrown or the process should stop without consuming excessive RAM.

Actural behavior The Dart process starts consuming more RAM continuously, and the freezed process gets stuck. The RAM usage keeps increasing until the Dart process is manually killed.

Environment Dart SDK version: 3.4.4 Flutter version: 3.22.3 stable freezed version: 2.4.7 freezed annotation version: 2.4.1 Operating System: Windows 10