Remove reference cycles in contentRecog objects#11510
Merged
Merged
Conversation
…s emitted by RecogResult objects should now inherit from to avoid creating reference cycles. the built-in ContentRecognizer TextInfos now do this.
LeonarddeR
reviewed
Aug 19, 2020
LeonarddeR
left a comment
Collaborator
There was a problem hiding this comment.
Couldn't we avoid patching altogehter by implementing updateSelection and updateCaret on BaseContentRecogTextInfo? We can keep the patching behavior for TextInfos not inherriting from BaseContentRecogTextInfo and remove it in 2021.1?
Member
Author
|
Errr... that is exactly what it does... unless I have made a mistake?
BaseContentRecogTextInfo inherits from _ReviewCursorTextInfo, which
provides updateCaret and updateSelection. RecogResultNVDAObject's
makeTextInfo method now only patches if the TextInfo is not a
BaseContentRecogTextInfo.
Note the patch call should be the same indentation as the deprecation
warning.
|
feerrenrut
previously approved these changes
Aug 19, 2020
feerrenrut
left a comment
Contributor
There was a problem hiding this comment.
Looks good overall, please add a deprecation label to the PR so we remember to come back and remove this.
LeonarddeR
previously approved these changes
Aug 19, 2020
LeonarddeR
left a comment
Collaborator
There was a problem hiding this comment.
Ugh yes, I'm sorry, missed the indentation there.
2366464
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to issue number:
Follow up from pr #11499
Summary of the issue:
contentRecog.regogUI.RecogResultNVDAObject causes a reference cycle, and therefore warnings are logged about this when garbage collecting.
The RecogResultNVDAObject stores a TextInfo instance as _selection on itself. But, it also patches the TextInfo's updateCaret and updateSelection methods to use self._selection. It is the fact these lambdas reference self (the RecogResultNVDAObject and they are stored on the TextInfo instance, thus a reference cycle.
Description of how this pull request fixes the issue:
Added a new contentRecog.BaseContentRecogTextInfo class which all TextInfos emitted by ContentRecogResult must inherit from. The built-in contentRecog TextInfos all do this now.
The BaseContentRecogTextInfo provides updatecaret and updateSelection implementations that use obj._selection. In fact, cursorManager._reviewCursorTextInfo was able to provide just this.
So for the built-in contentRecogs in NVDA, reference cycles have been addressed.
However, The RecogResultNVDAObject's makeTextInfo method now also logs a warning if it sees a TextInfo that does not correctly inherit from BaseContentRecogTextInfo, and still supports other TextInfos by continuing to patch causing the reference cycles.
This should obviously be removed in 2021.1
Testing performed:
Ran OCR (NvDA+r) on a File Explorer Window and arrowed up and down the text. Also arrowed to a particular file name and pressed enter, ensuring that that file was clicked.
Ensured that garbage collection errors/warnings related to contentRecog no longer appeared in the log.
Known issues with pull request:
None.
Change log entry:
None needed.