diff --git a/CHANGELOG.md b/CHANGELOG.md index 9dd84c5..17c14d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,37 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## 2025-10-20 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`cherrypick` - `v3.0.2`](#cherrypick---v302) + - [`cherrypick_flutter` - `v3.0.2`](#cherrypick_flutter---v302) + - [`talker_cherrypick_logger` - `v3.0.2`](#talker_cherrypick_logger---v302) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `cherrypick_flutter` - `v3.0.2` + - `talker_cherrypick_logger` - `v3.0.2` + +--- + +#### `cherrypick` - `v3.0.2` + + - **FIX**(test): fix warning. + - **FIX**(scope): properly clear binding and module references on dispose. + + ## 2025-09-09 ### Changes diff --git a/benchmark_di/pubspec.lock b/benchmark_di/pubspec.lock index f83de7f..ec65489 100644 --- a/benchmark_di/pubspec.lock +++ b/benchmark_di/pubspec.lock @@ -47,7 +47,7 @@ packages: path: "../cherrypick" relative: true source: path - version: "3.0.0" + version: "3.0.1" collection: dependency: transitive description: diff --git a/cherrypick/CHANGELOG.md b/cherrypick/CHANGELOG.md index 5d26e63..64a33bb 100644 --- a/cherrypick/CHANGELOG.md +++ b/cherrypick/CHANGELOG.md @@ -1,3 +1,8 @@ +## 3.0.2 + + - **FIX**(test): fix warning. + - **FIX**(scope): properly clear binding and module references on dispose. + ## 3.0.1 - **DOCS**: add Netlify deployment status badge to README files. diff --git a/cherrypick/lib/src/scope.dart b/cherrypick/lib/src/scope.dart index 608f72d..cba58c8 100644 --- a/cherrypick/lib/src/scope.dart +++ b/cherrypick/lib/src/scope.dart @@ -498,5 +498,10 @@ class Scope with CycleDetectionMixin, GlobalCycleDetectionMixin { await d.dispose(); } _disposables.clear(); + + // Clear modules + _modulesList.clear(); + // Clear binding-index + _bindingResolvers.clear(); } } diff --git a/cherrypick/pubspec.yaml b/cherrypick/pubspec.yaml index caaaa4a..e6d1df8 100644 --- a/cherrypick/pubspec.yaml +++ b/cherrypick/pubspec.yaml @@ -1,6 +1,6 @@ name: cherrypick description: Cherrypick is a small dependency injection (DI) library for dart/flutter projects. -version: 3.0.1 +version: 3.0.2 homepage: https://cherrypick-di.netlify.app documentation: https://cherrypick-di.netlify.app/docs/intro repository: https://github.com/pese-git/cherrypick diff --git a/cherrypick/test/binding_memory_leak_test.dart b/cherrypick/test/binding_memory_leak_test.dart new file mode 100644 index 0000000..d1b9dcc --- /dev/null +++ b/cherrypick/test/binding_memory_leak_test.dart @@ -0,0 +1,65 @@ +import 'dart:async'; +import 'package:cherrypick/cherrypick.dart'; +import 'package:test/test.dart'; + +class HeavyService implements Disposable { + static int instanceCount = 0; + HeavyService() { + instanceCount++; + print('HeavyService created. Instance count: ' + '\u001b[32m$instanceCount\u001b[0m'); + } + + @override + void dispose() { + instanceCount--; + print('HeavyService disposed. Instance count: ' + '\u001b[31m$instanceCount\u001b[0m'); + } + + static final Finalizer _finalizer = Finalizer((msg) { + print('GC FINALIZED HeavyService: $msg'); + }); + void registerFinalizer() => _finalizer.attach(this, toString(), detach: this); +} + +class HeavyModule extends Module { + @override + void builder(Scope scope) { + bind().toProvide(() => HeavyService()); + } +} + +void main() { + test('Binding memory is cleared after closing and reopening scope', () async { + final root = CherryPick.openRootScope(); + for (int i = 0; i < 10; i++) { + print('\nIteration $i -------------------------------'); + final subScope = root.openSubScope('leak-test-scope'); + subScope.installModules([HeavyModule()]); + final service = subScope.resolve(); + expect(service, isNotNull); + await root.closeSubScope('leak-test-scope'); + // Dart GC не сразу удаляет освобождённые объекты, добавляем паузу и вызываем GC. + await Future.delayed(const Duration(milliseconds: 200)); + } + + // Если dispose не вызвался, instanceCount > 0 => утечка. + expect(HeavyService.instanceCount, equals(0)); + }); + + test('Service is finalized after scope is closed/cleaned', () async { + final root = CherryPick.openRootScope(); + HeavyService? ref; + { + final sub = root.openSubScope('s'); + sub.installModules([HeavyModule()]); + ref = sub.resolve(); + ref.registerFinalizer(); + expect(HeavyService.instanceCount, 1); + await root.closeSubScope('s'); + } + await Future.delayed(const Duration(seconds: 2)); + expect(HeavyService.instanceCount, 0); + }); +} diff --git a/cherrypick_flutter/CHANGELOG.md b/cherrypick_flutter/CHANGELOG.md index 1650901..e215efe 100644 --- a/cherrypick_flutter/CHANGELOG.md +++ b/cherrypick_flutter/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.0.2 + + - Update a dependency to the latest release. + ## 3.0.1 - **DOCS**: add Netlify deployment status badge to README files. diff --git a/cherrypick_flutter/pubspec.yaml b/cherrypick_flutter/pubspec.yaml index 3c694bf..c74ca7e 100644 --- a/cherrypick_flutter/pubspec.yaml +++ b/cherrypick_flutter/pubspec.yaml @@ -1,6 +1,6 @@ name: cherrypick_flutter description: "Flutter library that allows access to the root scope through the context using `CherryPickProvider`." -version: 3.0.1 +version: 3.0.2 homepage: https://cherrypick-di.netlify.app documentation: https://cherrypick-di.netlify.app/docs/intro repository: https://github.com/pese-git/cherrypick @@ -19,7 +19,7 @@ environment: dependencies: flutter: sdk: flutter - cherrypick: ^3.0.1 + cherrypick: ^3.0.2 dev_dependencies: flutter_test: diff --git a/examples/client_app/pubspec.lock b/examples/client_app/pubspec.lock index 8b4b7af..254945b 100644 --- a/examples/client_app/pubspec.lock +++ b/examples/client_app/pubspec.lock @@ -127,28 +127,28 @@ packages: path: "../../cherrypick" relative: true source: path - version: "3.0.0" + version: "3.0.1" cherrypick_annotations: dependency: "direct main" description: path: "../../cherrypick_annotations" relative: true source: path - version: "3.0.0" + version: "3.0.1" cherrypick_flutter: dependency: "direct main" description: path: "../../cherrypick_flutter" relative: true source: path - version: "3.0.0" + version: "3.0.1" cherrypick_generator: dependency: "direct dev" description: path: "../../cherrypick_generator" relative: true source: path - version: "3.0.0" + version: "3.0.1" clock: dependency: transitive description: @@ -574,4 +574,4 @@ packages: version: "3.1.3" sdks: dart: ">=3.8.0 <4.0.0" - flutter: ">=3.18.0-18.0.pre.54" + flutter: ">=3.32.0" diff --git a/examples/postly/pubspec.lock b/examples/postly/pubspec.lock index 505ed1b..8c4644d 100644 --- a/examples/postly/pubspec.lock +++ b/examples/postly/pubspec.lock @@ -175,14 +175,14 @@ packages: path: "../../cherrypick" relative: true source: path - version: "3.0.0" + version: "3.0.1" cherrypick_annotations: dependency: "direct main" description: path: "../../cherrypick_annotations" relative: true source: path - version: "3.0.0" + version: "3.0.1" cherrypick_generator: dependency: "direct dev" description: @@ -920,7 +920,7 @@ packages: path: "../../talker_cherrypick_logger" relative: true source: path - version: "3.0.0" + version: "3.0.1" talker_dio_logger: dependency: "direct main" description: @@ -1131,4 +1131,4 @@ packages: version: "2.2.2" sdks: dart: ">=3.8.0 <4.0.0" - flutter: ">=3.29.0" + flutter: ">=3.32.0" diff --git a/talker_cherrypick_logger/CHANGELOG.md b/talker_cherrypick_logger/CHANGELOG.md index 9db4578..30e8d8a 100644 --- a/talker_cherrypick_logger/CHANGELOG.md +++ b/talker_cherrypick_logger/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.0.2 + + - Update a dependency to the latest release. + ## 3.0.1 - **DOCS**: add Netlify deployment status badge to README files. diff --git a/talker_cherrypick_logger/pubspec.yaml b/talker_cherrypick_logger/pubspec.yaml index 93a2a36..4a3422e 100644 --- a/talker_cherrypick_logger/pubspec.yaml +++ b/talker_cherrypick_logger/pubspec.yaml @@ -1,6 +1,6 @@ name: talker_cherrypick_logger description: A Talker logger integration for CherryPick DI to observe and log DI events and errors. -version: 3.0.1 +version: 3.0.2 homepage: https://cherrypick-di.netlify.app documentation: https://cherrypick-di.netlify.app/docs/intro repository: https://github.com/pese-git/cherrypick @@ -18,7 +18,7 @@ environment: # Add regular dependencies here. dependencies: talker: ^5.0.0 - cherrypick: ^3.0.1 + cherrypick: ^3.0.2 dev_dependencies: