TestLocalVarFree verifies that tables and user user datas which are no longer referenced by the lua script are correctly gc-ed. There was a bug in gopher lua where local vars were not being gc-ed in all circumstances.
(t *testing.T)
| 113 | // TestLocalVarFree verifies that tables and user user datas which are no longer referenced by the lua script are |
| 114 | // correctly gc-ed. There was a bug in gopher lua where local vars were not being gc-ed in all circumstances. |
| 115 | func TestLocalVarFree(t *testing.T) { |
| 116 | s := ` |
| 117 | function Test(a, b, c) |
| 118 | local a = { v = allocFinalizer() } |
| 119 | local b = { v = allocFinalizer() } |
| 120 | return a |
| 121 | end |
| 122 | Test(1,2,3) |
| 123 | for i = 1, 100 do |
| 124 | collectgarbage() |
| 125 | if countFinalizers() == 0 then |
| 126 | return |
| 127 | end |
| 128 | sleep(100) |
| 129 | end |
| 130 | error("user datas not finalized after 100 gcs") |
| 131 | ` |
| 132 | L := NewState() |
| 133 | L.SetGlobal("allocFinalizer", L.NewFunction(allocFinalizerUserData)) |
| 134 | L.SetGlobal("sleep", L.NewFunction(sleep)) |
| 135 | L.SetGlobal("countFinalizers", L.NewFunction(countFinalizers)) |
| 136 | defer L.Close() |
| 137 | if err := L.DoString(s); err != nil { |
| 138 | t.Error(err) |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | func TestGlua(t *testing.T) { |
| 143 | testScriptDir(t, gluaTests, "_glua-tests") |