-
Notifications
You must be signed in to change notification settings - Fork 3k
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
base: main
Are you sure you want to change the base?
[vector_graphics] Fix memory leaks and activate leak testing [prod-leak-fix] #8373
Conversation
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
The package manipulates disposable objects. This PR
See the documentation: https://github.com/dart-lang/leak_tracker/blob/main/doc%2Fleak_tracking%2FDETECT.md
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style, or this PR is exempt from CHANGELOG changes.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.