Lua memory leakage issue?
Posted: Sun Nov 30, 2014 4:24 am
Ok, so I've read about some issues regarding memory leakage due to the SDK and/or Lua itself. I don't quite understand what's going on so I thought I'd do a simple test to try and understand and capture what's happening:
A simple test:
- Restart ESP
- Print a string
- Check memory
- Set a s string to "test"
- Check memory
- Print s string
- Check memory
- Set the same string to nil
- Check memory
RESULT: Memory lost!
This effect is worse the larger the element. If I did the same thing with a largish function and then set the function and all it's variables to nil, the lost memory is even greater.
Thoughts?
A simple test:
- Restart ESP
- Print a string
- Check memory
- Set a s string to "test"
- Check memory
- Print s string
- Check memory
- Set the same string to nil
- Check memory
RESULT: Memory lost!
Code: Select all
node.restart()
> "ʃ
æÿ[0C]G9ÿQˆBIb õ[11]™RClò)û
lua: cannot open init.lua
NodeMcu 0.9.2 build 20141129 powered by Lua 5.1.4
> print(node.heap())
21408
> print("test")
test
> print(node.heap())
21408
> -- No memory used
> s = "test"
> print(node.heap())
21128
> print(s)
test
> print(node.heap())
21128
> s = nil
> print(node.heap())
21224
> -- 5 minutes later
> print(node.heap())
21224
> -- Why? What happened to the (21408 - 21224 = 184 bytes)?
This effect is worse the larger the element. If I did the same thing with a largish function and then set the function and all it's variables to nil, the lost memory is even greater.
Thoughts?