Skip to content

fix some leaks and minor changes#3218

Open
freebeartogoodhome wants to merge 2 commits into
lichess-org:mainfrom
freebeartogoodhome:leaksandsuch
Open

fix some leaks and minor changes#3218
freebeartogoodhome wants to merge 2 commits into
lichess-org:mainfrom
freebeartogoodhome:leaksandsuch

Conversation

@freebeartogoodhome
Copy link
Copy Markdown
Contributor

lib/src/view/account/edit_profile_screen.dart
fixes a potential memory leak
Linked the focusNode from Autocomplete<String> to _countryFocusNode
Added _countryFocusNode.dispose()

lib/src/view/message/contacts_screen.dart
added _controller.dispose();
added _focusNode.dispose();
Used Riverpod's built-in ref.debounce() instead of a manual debouncer that we also have to cancel later.

lib/src/view/user/player_screen.dart
Ensure we really stop watching our friends.
There is a potential race condition if the user pops the PlayerScreen off the navigation stack and then the (context.mounted == false) and we don't stop watching friends.

lib/src/view/user/search_screen.dart
fixed typo in the variable name _kSaveHistoryDebounceTimer
added _saveHistoryDebouncer.cancel
removed a ref.read because it is redundant when we are already watching

lib/src/widgets/emoji_picker/emoji_picker.dart
added _debouncer.cancel();

lib/src/widgets/platform_search_bar.dart
Fixes a potential memory leak. When a parent widget rebuilds and passes a new TextEditingController the old controller still holds a reference to _onTextChanged.
didUpdateWidget swaps the listener to the new controller.

lib/src/view/broadcast/broadcast_game_screen.dart
fixes a memory leak in the BroadcastGameScreen by replacing TapGestureRecognizer with GestureDetector
TapGestureRecognizer instances inside TextSpan must be manually disposed of to prevent memory leaks. They were never being cleaned up.
Removed import 'package:flutter/gestures.dart'; since it's no longer used,
Made sure the broadcast pgn text still looks fine.

screenshotbroadcastpgn

Text(context.l10n.countryRegion, style: Styles.formLabel),
const SizedBox(height: 6.0),
Autocomplete<String>(
focusNode: _countryFocusNode,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't see how this could be a memory leak since the argument was not provided.

Do you assume that internally, Flutter does not dispose the focus node? While it is possible, I doubt it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll look into that. That was my understanding but I will check everything out to be 100% sure.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Bad news first:
That code ran, analyzed, tested, etc. but apparently I didn't remember to go to the profile screen and attempt to change the country. 😩 Right now it will give:

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown building Autocomplete<String>(dirty):
'package:flutter/src/widgets/autocomplete.dart': Failed assertion: line 191 pos 15: '(focusNode ==
null) == (textEditingController == null)': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially
more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=02_bug.yml

What I read about the old code was right though. I stress tested it and can see it leaking.
stress_test

I fixed the assertion and did a memory test with the new one. It is showing a delta of 0 now.

recognizer: TapGestureRecognizer()
..onTap = () => launchUrlString(url),
),
return GestureDetector(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please explain this change, I don't see why it is better.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was because GestureDetector manages its own disposal and we were not disposing the TapGestureRecognizer. If the clicking behavior is going to be worse then I didn't know that. The display worked fine for me and I clicked on everything fine in my testing.

@freebeartogoodhome
Copy link
Copy Markdown
Contributor Author

I found [RawAutocomplete] Remove assert that don't seem to be needed from 2023 so I guess I don't need to tell them about that.

@veloce veloce requested a review from Copilot May 25, 2026 09:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment on lines 33 to 39
final _formData = <String, dynamic>{
'flag': null,
'location': null,
'bio': null,
'flair': null,
'realName': null,
'lastName': null,
'fideRating': null,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I set a flair with this build, and cleared the flair too. It worked for me.

Now I'm really, really taking a break.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants