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

clear_panes and memory leak #4959

Closed
peppedilillo opened this issue Sep 1, 2024 · 3 comments · Fixed by #4964
Closed

clear_panes and memory leak #4959

peppedilillo opened this issue Sep 1, 2024 · 3 comments · Fixed by #4964

Comments

@peppedilillo
Copy link

peppedilillo commented Sep 1, 2024

Hello! Thanks for this wonderful framework, having a blast with it.
I seem to have a memory leak with my app. I suspect the problem to be caused by my usage of the TabbedContent's method clear_panes(). I have a TabbedContent which i want to refresh every time a user provides a file input. The widget contains tabs which reference large tables. I was expecting clear_panes() to remove all references to the stale tabs, letting the stale tables to the garbage collector. This doesn't seem to be happening. I have reproduced this behavior with the following MRE:

from textual.app import App
from textual.widgets import Header, TabbedContent, Footer, TabPane
from textual import work


class MyTabPane(TabPane):
    def __init__(self):
        super().__init__("table")
        self.df = [1] * 100_000_000


class Explorer(App):
    BINDINGS = [
        ("ctrl+o", "add_table", "add table"),
    ]

    def __init__(self):
        super().__init__()

    def compose(self):
        yield Header(show_clock=False)
        yield TabbedContent()
        yield Footer()

    @work
    async def action_add_table(self):
        tabs = self.query_one(TabbedContent)
        tabs.loading = True
        await tabs.clear_panes()
        await tabs.add_pane(MyTabPane())
        tabs.loading = False


if __name__ == "__main__":
    app = Explorer()
    app.run()

Pressing ctrl+o repeatedly I can see an increase in the process's memory usage. I am on MacOS Ventura, iterm2.
What can I do to solve this problem with my program?
Thank you.

Copy link

github-actions bot commented Sep 1, 2024

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

@willmcgugan
Copy link
Collaborator

Will take a look later. In the meantime you could do del self.df in on_unmount

Copy link

github-actions bot commented Sep 9, 2024

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

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 a pull request may close this issue.

2 participants