Overzealous garbage collection(?)
Open
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 491
- Forks
- 81
- PR merge metrics
- No merged PRs in 30d
Description
Not-so-minimal example (Lua 5.3):
local Gtk = require('lgi').Gtk
local GObject = require('lgi').GObject
local Foo = require('lgi').package('Foo')
local CrashModel = Foo:class('CrashModel', GObject.Object, { Gtk.TreeModel })
do local CrashModel = CrashModel._override['Gtk.TreeModel']
function CrashModel:get_column_type(col)
if col == 0 then
return GObject.Type.STRING
end
end
function CrashModel:get_iter(path)
local i, i2 = table.unpack(path:get_indices())
if i2 then
return nil
end
return Gtk.TreeIter { stamp = i }
end
function CrashModel:iter_n_children(iter)
if iter == nil then
return 500
end
return 0
end
function CrashModel:get_value(iter, col)
if col == 0 then
return GObject.Value(GObject.Type.STRING, "Blah")
end
end
function CrashModel:get_path(iter)
return Gtk.TreePath.new_from_indices { iter.stamp }
end
function CrashModel:iter_next(iter, ...)
if (iter.stamp + 1) >= 500 then
return false
end
iter.stamp = iter.stamp + 1
return true
end
end
collectgarbage("stop") -- Thanks to this line, this code leaks memory. If I remove it, the program crashes instead.
local iv = Gtk.IconView()
iv:set_model(CrashModel())
iv:set_markup_column(0)
local wind = Gtk.Window()
wind:add(iv)
wind:show_all()
wind.on_delete_event = Gtk.main_quit
Gtk.main()
I did some investigating, and it turns out ffi_closure_free is called on a closure which is still referenced inside a GtkTreeModelIface structure used by Gtk.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Lua 5.3 example and tracing the lifetime of the closure referenced by the GtkTreeModelIface structure. Investigate the ffi_closure_free call and compare behavior with garbage collection stopped; done means the example no longer leaks or crashes during Gtk.main().
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100