Skip to content

Remove reference cycles in contentRecog objects#11510

Merged
michaelDCurran merged 2 commits into
masterfrom
removeContentRecogReferenceCycles
Aug 20, 2020
Merged

Remove reference cycles in contentRecog objects#11510
michaelDCurran merged 2 commits into
masterfrom
removeContentRecogReferenceCycles

Conversation

@michaelDCurran

Copy link
Copy Markdown
Member

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.

…s emitted by RecogResult objects should now inherit from to avoid creating reference cycles. the built-in ContentRecognizer TextInfos now do this.
@michaelDCurran michaelDCurran added this to the 2020.3 milestone Aug 18, 2020

@LeonarddeR LeonarddeR left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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?

@michaelDCurran

michaelDCurran commented Aug 19, 2020 via email

Copy link
Copy Markdown
Member Author

feerrenrut
feerrenrut previously approved these changes Aug 19, 2020

@feerrenrut feerrenrut left a comment

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.

Looks good overall, please add a deprecation label to the PR so we remember to come back and remove this.

Comment thread source/contentRecog/recogUi.py
LeonarddeR
LeonarddeR previously approved these changes Aug 19, 2020

@LeonarddeR LeonarddeR left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ugh yes, I'm sorry, missed the indentation there.

@michaelDCurran michaelDCurran dismissed stale reviews from LeonarddeR and feerrenrut via 2366464 August 20, 2020 05:50
@michaelDCurran michaelDCurran merged commit b65608a into master Aug 20, 2020
@michaelDCurran michaelDCurran deleted the removeContentRecogReferenceCycles branch August 20, 2020 05:50
@seanbudd seanbudd added the deprecated/2021.1 Label used to track deprecations due for removal in the 2021.1 release label Mar 5, 2021
@seanbudd seanbudd mentioned this pull request Mar 5, 2021
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deprecated/2021.1 Label used to track deprecations due for removal in the 2021.1 release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants