# \[Lua\] - Local scoped variables not cleared

**URL:** <https://forum.heroiclabs.com/t/lua-local-scoped-variables-not-cleared/3894>\
**Category:** Runtime Framework\
**Tags:** server-framework, lua\
**Created:** [May 24, 2023, 10:04am UTC](https://forum.heroiclabs.com/t/lua-local-scoped-variables-not-cleared/3894 "2023-05-24T10:04:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eatos](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/eatos/32/1656_2.png) [@Eatos](https://forum.heroiclabs.com/u/Eatos)\
**Post date:** [May 24, 2023, 10:04am UTC](https://forum.heroiclabs.com/t/lua-local-scoped-variables-not-cleared/3894/1 "2023-05-24T10:04:22Z")

</div>

It seams that local scoped variables are not being correctly gc-ed when they are not longer used, thus memory just keeps growing.  
Example:  
When using stock/vanilla Lua 5.1 following code yields this:

```auto
local d = {}
do
    local a = {}
	local b = 1
    d['a'] = a
    d['b'] = b
end

for k, v in pairs(d) do
    print(k, v)
end
collectgarbage()
print("=====================")
for k, v in pairs(d) do
    print(k, v)
end

```

```auto
a	table: 0x006b8638
b	1
=====================
b	1

```

While in docker the same code does not release the local scoped variable and yields this.

```auto
2023-05-24 11:58:13 a table: 0xc0012a4000
2023-05-24 11:58:13 b 1
2023-05-24 11:58:13 =====================
2023-05-24 11:58:13 a table: 0xc0012a4000
2023-05-24 11:58:13 b 1

```

I managed to track same issue in gopher-lua it was fixed but same changes i haven’t seen in nakama pull.  
[Local Memory Scope GC](https://github.com/yuin/gopher-lua/issues/227)

collecgarbage is implemented in nakama, and it clears whole memory of Go rather than just Lua VMs

So i am not 100% sure , should in nakama case locally scoped variables be gc-ed or not, but anyway reporting it for clarification.

1. Versions: Nakama {3.16.0}, { Docker},
2. Server Framework Runtime: Lua

---

<div class="post-metadata">

**Author:** ![tom](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/tom/32/676_2.png) [@tom](https://forum.heroiclabs.com/u/tom)\
**Post date:** [May 24, 2023, 11:47am UTC](https://forum.heroiclabs.com/t/lua-local-scoped-variables-not-cleared/3894/2 "2023-05-24T11:47:04Z")

</div>

Hi @Eatos,

Please could you file an issue on our [Nakama GitHub Issue Tracker](https://github.com/heroiclabs/nakama/issues) and we will investigate.
