MCPcopy Index your code
hub / github.com/yuin/gopher-lua / TestLocalVarFree

Function TestLocalVarFree

script_test.go:115–140  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
115func 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
142func TestGlua(t *testing.T) {
143 testScriptDir(t, gluaTests, "_glua-tests")

Callers

nothing calls this directly

Calls 6

DoStringMethod · 0.80
NewStateFunction · 0.70
ErrorMethod · 0.65
SetGlobalMethod · 0.45
NewFunctionMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…