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

Memory Leak in Table class! #47

Closed
816-8055 opened this issue Nov 22, 2016 · 2 comments
Closed

Memory Leak in Table class! #47

816-8055 opened this issue Nov 22, 2016 · 2 comments

Comments

@816-8055
Copy link
Contributor

816-8055 commented Nov 22, 2016

Each redraw of a Table instance consumes an average of 21kB RAM on an "empty" table.
With a filled Table it's even more.

To prove the problem, I wrote a small application which refreshes 100 times a second, calculates the average additional consumed memory and shows also the total consumed memory:

import psutil
import tkinter as tk
import pandastable

FREQ = 100  # redraws per second


def update_title():
    global N, S
    mem = me.memory_full_info().uss
    table.redraw()
    diff = me.memory_full_info().uss - mem
    S += diff
    N += 1
    root.title('total: {:.2f}MB - added per redraw: {:.2f}kB'
               .format(mem / 1000**2, (S/N)/1000))
    root.after(1000//FREQ, update_title)

if __name__ == '__main__':
    N = 0
    S = 0
    me = psutil.Process()
    root = tk.Tk()
    frame = tk.Frame(root)
    table = pandastable.Table(frame)
    table.show()
    frame.pack(fill='both', expand=True)
    root.after(100, update_title)
    smu = me.memory_full_info().uss
    root.mainloop()
    print('{:.2f}MB'.format((me.memory_full_info().uss-smu)/1000**2))

pandastable_memleak

@816-8055
Copy link
Contributor Author

Commenting out line 311 in file core.py reduces the memory usage by 3kB per redraw.
Creating a new canvas on each redraw doesn't look like a good idea to me!

    def redrawVisible(self, event=None, callback=None):
        """Redraw the visible portion of the canvas"""

        model = self.model
        #self.scratch = Canvas()
        self.rows = len(self.model.df.index)
        self.cols = len(self.model.df.columns)

@dmnfarrell
Copy link
Owner

Great. Not sure why this line was ever needed to be honest. Thanks for taking the time to check that. I will make a minor update soon and add that change in.

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

No branches or pull requests

2 participants