Unverified Commit bcb2ac5a authored by Dan Field's avatar Dan Field Committed by GitHub

docs for image disposal (#67066)

parent c9392da6
...@@ -284,7 +284,7 @@ typedef DecoderCallback = Future<ui.Codec> Function(Uint8List bytes, {int? cache ...@@ -284,7 +284,7 @@ typedef DecoderCallback = Future<ui.Codec> Function(Uint8List bytes, {int? cache
/// void _updateImage(ImageInfo imageInfo, bool synchronousCall) { /// void _updateImage(ImageInfo imageInfo, bool synchronousCall) {
/// setState(() { /// setState(() {
/// // Trigger a build whenever the image changes. /// // Trigger a build whenever the image changes.
/// _imageInfo?.image?.dispose(); /// _imageInfo?.dispose();
/// _imageInfo = imageInfo; /// _imageInfo = imageInfo;
/// }); /// });
/// } /// }
...@@ -292,7 +292,7 @@ typedef DecoderCallback = Future<ui.Codec> Function(Uint8List bytes, {int? cache ...@@ -292,7 +292,7 @@ typedef DecoderCallback = Future<ui.Codec> Function(Uint8List bytes, {int? cache
/// @override /// @override
/// void dispose() { /// void dispose() {
/// _imageStream.removeListener(ImageStreamListener(_updateImage)); /// _imageStream.removeListener(ImageStreamListener(_updateImage));
/// _imageInfo?.image?.dispose(); /// _imageInfo?.dispose();
/// _imageInfo = null; /// _imageInfo = null;
/// super.dispose(); /// super.dispose();
/// } /// }
......
...@@ -45,7 +45,7 @@ class ImageInfo { ...@@ -45,7 +45,7 @@ class ImageInfo {
/// ///
/// See also: /// See also:
/// ///
/// * [Image.clone] /// * [Image.clone], which describes how and why to clone images.
ImageInfo clone() { ImageInfo clone() {
return ImageInfo( return ImageInfo(
image: image.clone(), image: image.clone(),
...@@ -68,11 +68,15 @@ class ImageInfo { ...@@ -68,11 +68,15 @@ class ImageInfo {
/// ```dart /// ```dart
/// ImageInfo _imageInfo; /// ImageInfo _imageInfo;
/// set imageInfo (ImageInfo value) { /// set imageInfo (ImageInfo value) {
/// // If the image reference is exactly the same, or its a clone of the /// // If the image reference is exactly the same, do nothing.
/// // current reference, we can immediately dispose of it and avoid /// if (value == _imageInfo) {
/// // recalculating anything. /// return;
/// if (value == _imageInfo || value != null && _imageInfo != null && value.isCloneOf(_imageInfo)) { /// }
/// value?.dispose(); /// // If it is a clone of the current reference, we must dispose of it and
/// // can do so immediately. Since the underlying image has not changed,
/// // We don't have any additional work to do here.
/// if (value != null && _imageInfo != null && value.isCloneOf(_imageInfo)) {
/// value.dispose();
/// return; /// return;
/// } /// }
/// _imageInfo?.dispose(); /// _imageInfo?.dispose();
...@@ -467,7 +471,7 @@ abstract class ImageStreamCompleter with Diagnosticable { ...@@ -467,7 +471,7 @@ abstract class ImageStreamCompleter with Diagnosticable {
@visibleForTesting @visibleForTesting
bool get hasListeners => _listeners.isNotEmpty; bool get hasListeners => _listeners.isNotEmpty;
/// We should avoid disposing a completer if it has never had a listener, even /// We must avoid disposing a completer if it has never had a listener, even
/// if all [keepAlive] handles get disposed. /// if all [keepAlive] handles get disposed.
bool _hadAtLeastOneListener = false; bool _hadAtLeastOneListener = false;
......
...@@ -1249,8 +1249,8 @@ class _ImageState extends State<Image> with WidgetsBindingObserver { ...@@ -1249,8 +1249,8 @@ class _ImageState extends State<Image> with WidgetsBindingObserver {
/// ///
/// If the listener from this state is the last listener on the stream, the /// If the listener from this state is the last listener on the stream, the
/// stream will be disposed. To keep the stream alive, set `keepStreamAlive` /// stream will be disposed. To keep the stream alive, set `keepStreamAlive`
/// to true, which will add a passive listener on the stream and is compatible /// to true, which create [ImageStreamCompleterHandle] to keep the completer
/// with the [TickerMode] being off. /// alive and is compatible with the [TickerMode] being off.
void _stopListeningToStream({bool keepStreamAlive = false}) { void _stopListeningToStream({bool keepStreamAlive = false}) {
if (!_isListeningToStream) if (!_isListeningToStream)
return; return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment