-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Memory issue when sharing CancelToken between posts for IO implementation #2111
Comments
Could you attach the minimal reproducible example and some analysis graphs or details? |
This comment was marked as off-topic.
This comment was marked as off-topic.
@kuhnroyal I have been thinking about the cause of this issue for the last few days, it could be caused by referencing the resources of the request in callers like |
If yes, we might add a global map to cache the necessary instances for the corresponding cancel token. |
I tried to enable the new leak tracking but didn't get very far yet... |
@AlexV525 I haven't had time to followup, but yes, as mentioned in my first message, we found that the .whenComplete callback captures over the Request:
and whenComplete() also adds additional handlers each time it is called. So if a CancelToken is passed in to multiple fetches, it will keep accruing whenComplete handlers that all capture over individual requests. |
@kunstmusik Can you verify if #2252 fixes the issue? |
Package
dio
Version
5.4.0
Operating-System
Android
Output of
flutter doctor -v
Dart Version
3.1.3
Steps to Reproduce
Expected Result
No out of memory issues on Android.
Actual Result
Out of memory issues occur.
Dio's use of cancelFuture in dio/lib/src/adapters/io_adapter.dart differs from how it is used in browser_adapter.dart and exhibits different behavior. In IO, it captures on request in the callback to whenComplete in _fetch, which does not happen in the browser implementation.
This took us some time to discover as a memory leak issue. It would be great if this could be fixed, otherwise would love to see this documented so that future users will be aware of this issue.
The text was updated successfully, but these errors were encountered: