Skip to content
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

PR: Close memory leaks of CodeEditor and ShellWidget #18781

Merged
merged 8 commits into from
Jul 28, 2022

Conversation

impact27
Copy link
Contributor

@impact27 impact27 commented Jul 22, 2022

Description of Changes

  • Wrote at least one-line docstrings (for any new functions)
  • Added unit test(s) covering the changes (if testable)
  • Included a screenshot or animation (if affecting the UI, see Licecap)

Issue(s) Resolved

Fixes #18764

Affirmation

By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.

I certify the above statement is true and correct:

@pep8speaks
Copy link

pep8speaks commented Jul 22, 2022

Hello @impact27! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2022-07-28 21:49:56 UTC

@ccordoba12 ccordoba12 changed the base branch from master to 5.x July 22, 2022 13:49
@ccordoba12 ccordoba12 changed the base branch from 5.x to master July 22, 2022 13:50
@ccordoba12 ccordoba12 added this to the v5.3.3 milestone Jul 22, 2022
@ccordoba12
Copy link
Member

Hey @impact27, this is great! Thanks a lot for taking the time to fix these memory leaks!

Could you move your branch to 5.x so we can include your PR in our next release? For that, please execute the following commands:

git checkout close_leaks
git rebase --onto 5.x master close_leaks
git push -f origin close_leaks

@ccordoba12 ccordoba12 changed the base branch from master to 5.x July 22, 2022 17:47
@ccordoba12 ccordoba12 changed the base branch from 5.x to master July 22, 2022 17:47
@impact27 impact27 changed the base branch from master to 5.x July 23, 2022 06:45
@impact27 impact27 force-pushed the close_leaks branch 7 times, most recently from 7247f3c to d65dab1 Compare July 23, 2022 16:37
@impact27 impact27 force-pushed the close_leaks branch 2 times, most recently from 0749a64 to 4f07bda Compare July 24, 2022 12:41
@impact27
Copy link
Contributor Author

@ccordoba12 This is ready for review. The failures are unrelated to this PR

Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

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

Thanks @impact27 for your hard work on this one!

spyder/app/tests/test_mainwindow.py Outdated Show resolved Hide resolved
code_editor = main_window.editor.get_focus_widget()
# Show an error in the editor
code_editor.set_text("aaa")
del code_editor
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need to delete this CodeEditor instance at this point?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Otherwise a reference is kept which leads to leaking a CodeEditor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am checking the number of CodeEditor with a reference below, this would add one. Del only deletes the local ref, not the object itself (unless this is the last ref)

spyder/app/tests/test_mainwindow.py Show resolved Hide resolved
@@ -309,7 +309,7 @@ def document_did_close(self, params):
if id(codeeditor) == id(editor):
idx = i
break
if idx > 0:
if idx >= 0:
Copy link
Member

@ccordoba12 ccordoba12 Jul 25, 2022

Choose a reason for hiding this comment

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

Why is it necessary to add the equal sign here? Just asking because I don't understand it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this was an error in the code. If no CodeEdotor are found, the index should be -1, so you can check with index >=0 (and not >0 which leads to a leak)

spyder/plugins/editor/utils/decoration.py Show resolved Hide resolved
spyder/plugins/editor/widgets/editor.py Outdated Show resolved Hide resolved
spyder/plugins/ipythonconsole/widgets/client.py Outdated Show resolved Hide resolved
spyder/plugins/ipythonconsole/widgets/client.py Outdated Show resolved Hide resolved
spyder/plugins/ipythonconsole/widgets/main_widget.py Outdated Show resolved Hide resolved
spyder/plugins/ipythonconsole/widgets/main_widget.py Outdated Show resolved Hide resolved
Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

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

Last comment for you @impact27, then this should be ready.

spyder/app/tests/test_mainwindow.py Show resolved Hide resolved
spyder/config/main.py Outdated Show resolved Hide resolved
Quentin Peter added 6 commits July 28, 2022 23:44
more better
fix test


simpler tests
close_more_clients


Update main_widget.py
_close_client


cleanup close_client
Quentin Peter and others added 2 commits July 28, 2022 23:49
fix test
Co-authored-by: Carlos Cordoba <ccordoba12@gmail.com>
Update test_mainwindow.py
Update main.py
Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

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

Thanks @impact27 for your hard work on this one!

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.

Memory leak when closing editor or console tabs
3 participants