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

[vector_graphics] Fix memory leaks and activate leak testing [prod-leak-fix] #8373

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ValentinVignal
Copy link
Contributor

The package manipulates disposable objects. This PR

  • Fixes some memory leaks.
  • Activates leak testing to make sure disposable objects are correctly disposed.

See the documentation: https://github.com/dart-lang/leak_tracker/blob/main/doc%2Fleak_tracking%2FDETECT.md

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@ValentinVignal
Copy link
Contributor Author

cc @polina-c

@@ -746,7 +746,8 @@ class FlutterVectorGraphicsListener extends VectorGraphicsCodecListener {
listener = ImageStreamListener(
(ImageInfo image, bool synchronousCall) {
cacheCompleter.removeListener(listener);
_images[imageId] = image.image;
_images[imageId] = image.image.clone();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand what this is doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the test Can render VG with image from test/vector_graphics_test.dart, leak_tracker_flutter_testing was not happy because the ImageInfo was not disposed from this callback was never disposed.

So here I am disposing it. However, disposing it also disposes it image.image, that's why I'm cloning it first.

  Expected: leak free
    Actual: <Instance of 'Leaks'>
     Which: contains leaks:
            # The text is generated by leak_tracker.
            # For leak troubleshooting tips open:
            # https://github.com/dart-lang/leak_tracker/blob/main/doc/leak_tracking/TROUBLESHOOT.md
            notDisposed:
              total: 1
              objects:
                ImageInfo:
                  test: Can render VG with image
                  identityHashCode: 137082098
                  context:
                    start: >
                      #6_______dispatchFlutterEventToLeakTracker_(package:leak_tracker_flutter_testing/src/testing.dart:74:23)
                      #7______FlutterMemoryAllocations.dispatchObjectEvent_(package:flutter/src/foundation/memory_allocations.dart:249:23)
                      #8______FlutterMemoryAllocations.dispatchObjectCreated_(package:flutter/src/foundation/memory_allocations.dart:283:5)
                      #9______new_ImageInfo_(package:flutter/src/painting/image_stream.dart:51:34)
                      #10_____ImageInfo.clone_(package:flutter/src/painting/image_stream.dart:72:12)
                      #11_____ImageStreamCompleter.setImage_(package:flutter/src/painting/image_stream.dart:755:32)
                      #12_____StackZoneSpecification._registerUnaryCallback.<anonymous_closure>.<anonymous_closure>_(package:stack_trace/src/stack_zone_specification.dart:127:36)
                      #13_____StackZoneSpecification._run_(package:stack_trace/src/stack_zone_specification.dart:207:15)
                      #14_____StackZoneSpecification._registerUnaryCallback.<anonymous_closure>_(package:stack_trace/src/stack_zone_specification.dart:127:24)
                      #15______rootRunUnary_(dart:async/zone.dart:1422:47)
                      #16______CustomZone.runUnary_(dart:async/zone.dart:1324:19)
                      #17_____Future._propagateToListeners.handleValueCallback_(dart:async/future_impl.dart:902:45)
                      #18_____Future._propagateToListeners_(dart:async/future_impl.dart:931:13)
                      #19_____Future._completeWithValue_(dart:async/future_impl.dart:707:5)
                      <asynchronous_suspension>
            
            
  
  package:matcher                                              expect
  package:leak_tracker_testing/src/leak_testing.dart 69:24     LeakTesting.collectedLeaksReporter.<fn>
  package:leak_tracker_flutter_testing/src/testing.dart 70:37  maybeTearDownLeakTrackingForAll
  ===== asynchronous gap ===========================
  dart:async                                                   _CustomZone.registerBinaryCallback
  package:flutter_test/src/test_compat.dart 287:3              _tearDownForTestFile
  

Is there a better way you have in mind?

@polina-c polina-c changed the title [vector_graphics] Fix memory leaks and activate leak testing [vector_graphics] Fix memory leaks and activate leak testing [prod-leak-fix] Jan 7, 2025
@polina-c polina-c added the a: leak tracking Issues and PRs related to memory leaks detected by leak_tracker label Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: leak tracking Issues and PRs related to memory leaks detected by leak_tracker p: vector_graphics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants