Ticket #65 (closed defect: fixed)

Opened 12 months ago

Last modified 11 months ago

urwid.Listbox leaks memory - simple demo program attached

Reported by: ifreecarve Owned by: ian
Priority: major Milestone:
Component: unknown Version:
Keywords: memory leak, signals Cc:

Description

I traced a memory leak in my urwid app to the uriwd.ListBox? function. I have attached a script that demonstrates the behavior I see. Basically, the number of objects in memory just keeps increasing.

This is urwid 0.9.8.4-1 on Ubuntu Jaunty.

Change History

Changed 12 months ago by ifreecarve

Apparently I can't add attachments.

Inline, then:

#!/usr/bin/env python                                                                                                         

import urwid.curses_display
import urwid

# http://guppy-pe.sourceforge.net/                                                                                            
from guppy import hpy; hp = hpy()


start_leaking = False

def run():
    global start_leaking

    while True:
	keys = ui.get_input()
	if "q" in keys: exit()
	if "l" in keys:
	    start_leaking = True

	draw_screen()


def draw_screen():

    lw = urwid.SimpleListWalker([])
    if not start_leaking:
	banner = urwid.Text("Press l (lowercase L) to start leaking")
    else:
	banner = urwid.Text(
            "Leaking enabled!  "
	    + "Hold spacebar to accelerate it\n"
            + "You will see 'dict of 0xXXXXXX' rising up the usage chart")

	##### THIS IS WHERE THE LEAK IS                                                                                       
	lb = urwid.ListBox(lw)

    top = urwid.Frame(urwid.Filler(urwid.Text(str(hp.heap()))), banner)

    size = ui.get_cols_rows()
    canvas = top.render(size, focus=True)
    ui.draw_screen(size, canvas)


ui = urwid.curses_display.Screen()
ui.run_wrapper(run)


Changed 12 months ago by ian

Thanks for the report! I'll look into it when I have some time.

Changed 11 months ago by ian

  • status changed from new to assigned

Good find. This is a leak in my signal connection code. Signals._connections is the dictionary that is growing without bound. I will have to revisit my weakref usage there with a clear head.

Ian

Changed 11 months ago by ian

  • keywords signals added; listbox removed

Changed 11 months ago by ian

Here's a fix. I don't love it because it involved attaching a magic attribute to the objects sending the signals, but it does solve the problem on my end in a pretty simple way.

https://excess.org/hg/urwid-0.9.8/rev/6fa8ec983995

Changed 11 months ago by ian

  • status changed from assigned to closed
  • resolution set to fixed

fixed in [5c1c07c07186] in dev version

Note: See TracTickets for help on using tickets.