Ticket #1251 (accepted defect)

Opened 3 years ago

Last modified 15 months ago

ListStore+TreeView leaks memory when destroyed

Reported by: guest Owned by: dmwit
Priority: normal Milestone:
Component: general (Gtk+, Glib) Version: 0.12.4
Keywords: Cc: randrew@…

Description

Creating a ListStore? and TreeView? appears to leak the memory used by its rows when the TreeView? is destroyed with widgetDestroy. Or perhaps I am doing something incorrectly. I constructed a trivial example that, when a button is clicked, creates TreeView?+ListStore? and fills it with 10000 randomly generated rows of Strings after destroying the previous TreeView?. The Strings appear to never be collected.

Attachments

Leak.hs (1.9 kB) - added by guest 3 years ago.
Demonstration of the leak

Change History

Changed 3 years ago by guest

Demonstration of the leak

Changed 16 months ago by dmwit

  • owner changed from somebody to dmwit
  • status changed from new to accepted
  • version changed from 0.11.0 to 0.12.4

I spent a little time today making the demo of the leak smaller. I'm not sure this is minimal yet, but I need to stop for the day, so here's the progress I've made. To observers: be sure to set an appropriate upper limit on your RTS' heap (8M or so seems to be enough for the non-leaking version) if you decide to try running this program!

import Control.Monad
import Graphics.UI.Gtk

main = initGUI >> forever (do
    (treeView, listStore) <- makeListView
    -- Uncomment the following line to stop leaking memory.
    --listStoreClear listStore
    widgetDestroy treeView
    )

makeListView = do
    lstore <- listStoreNew []
    tview  <- treeViewNewWithModel lstore
    tcol   <- treeViewColumnNew
    tcell  <- cellRendererTextNew
    treeViewColumnPackStart tcol tcell False
    cellLayoutSetAttributes tcol tcell lstore $
        \x -> [cellText := x]
    treeViewAppendColumn tview tcol
    mapM_ (listStoreAppend lstore . show) [0..10000 :: Int]
    return (tview, lstore)

Changed 15 months ago by dmwit

Another note to self: https://developer.gnome.org/gtk2/stable/TreeWidget.html looks like good reading.

Changed 15 months ago by dmwit

See also Ticket #1167.

Changed 15 months ago by dmwit

I guess CustomStore? probably ought to hook into the GObject system and register a function to run when it's not referenced any more. https://developer.gnome.org/gobject/stable/howto-gobject-destruction.html

Note: See TracTickets for help on using tickets.