Open EArminjon opened 7 months ago
on Linux same issue, actually it crush quicker.
For those facing this issue, the following solution/workaround worked for me. https://github.com/flutter/flutter/issues/102140#issuecomment-2031004058
@EArminjon I found using the errorListener
makes Flutter unable to remove unused instances of the CachedNetworkImage with the garbage collector. If you don't mind having error handling, try removing the errorListener
property and check if that helps with the memory leaks.
Reference to https://github.com/Baseflow/flutter_cached_network_image/issues/951
Any update for this Issue?
I create a simple app and confirmed that errorListener
causing memory leak.
bug_cached_network_image
with setting errorListener
without setting errorListener
Sadly we also bumped into this very serious issue. If you check ImageCompleterHandler's dispose
method you can see that it calls maybeDispose
on the ImageStreamCompleter
object. This maybeDispose method does not do anything if the completer has any listeners, so basically nothing is disposed from the memory.
Replacing addListener()
by addEphemeralErrorListener()
(https://github.com/flutter/flutter/commit/aeddab428d4d51dc2e7b070969572067a37d3650)?) would solve this issue. The only problem is: this method is only available since 3.16
, but this package has flutter: '>=3.10.0'
requirements in its pubspec.yaml, so I'm not sure how could be this implemented with backward compatibility:
if (errorListener != null) {
imageStreamCompleter.addEphemeralErrorListener((exception, stackTrace) {
errorListener?.call(exception);
});
}
Without the listener all errors are forwarded to FlutterError.onError
which spams them to Crashlytics if its connected, so it is a tricky situation.
I also confirm errorListener
cause memory leak. Is this a bug of this package or a Flutter bug?
@XuanTung95 This is a bug of this package, and I think it is related to this PR https://github.com/Baseflow/flutter_cached_network_image/pull/891
🐛 Bug Report
On real device Android & iOS this package have a memory leak.
Our app got some crash in production because of this issue : we have a long list of product inside a paginated infinite list. User can scroll on it and some of them reported crash. After investigation we discover this memory leak.
Expected behavior
Constant RSS usage
Reproduction steps
Use code bellow and check on devtools the memory usage graph.
With CachedNetworkImage : (increase during scroll)
With Image.network: (stable during scroll)
Configuration
Versions:
Platform: