-->
Page 1 of 1

Heap Leak on if

PostPosted: Sun Nov 30, 2014 4:16 pm
by GeoNomad
Maybe I just don't know how to use Lua yet, but this was causing issues and I narrowed it down to a test case:

Code: Select all
NodeMcu 0.9.2 build 20141124  powered by Lua 5.1.4
> tmr.stop()
>
> if (cat == nil) then
>>    cat = 5
>>    end
> print(node.heap())
20360
>
> if (cat == nil) then
>>    cat = 5
>>    end
> print(node.heap())
19784
>
> if (cat == nil) then
>>    cat = 5
>>    end
> print(node.heap())
19056
>
> if (cat == nil) then
>>    cat = 5
>>    end
> print(node.heap())
18480
>


If I am doing something wrong, or if this has been fixed in the past week, please let me know.

Re: Heap Leak on if

PostPosted: Mon Dec 01, 2014 7:18 am
by ThomasW
GeoNomad wrote:Maybe I just don't know how to use Lua yet, but this was causing issues and I narrowed it down to a test case:

Code: Select all
NodeMcu 0.9.2 build 20141124  powered by Lua 5.1.4
> tmr.stop()
>
> if (cat == nil) then
>>    cat = 5
>>    end
> print(node.heap())
20360
>
> if (cat == nil) then
>>    cat = 5
>>    end
> print(node.heap())
19784
>
> if (cat == nil) then
>>    cat = 5
>>    end
> print(node.heap())
19056
>
> if (cat == nil) then
>>    cat = 5
>>    end
> print(node.heap())
18480
>


If I am doing something wrong, or if this has been fixed in the past week, please let me know.


Hi
just found out - don't rely on any memory-related tests entered directly into the commandline-interpreter
put the above code into a file and make a dofile:

Code: Select all> node.restart()
> �!
       �����!��1�)]��
lua: cannot open init.lua
NodeMcu 0.9.2 build 20141130  powered by Lua 5.1.4
> dofile("ifi")
20288
20248
20248
20248


The commandline seems to lack memory management completely - be patient and enter/paste the following highly sophisticated code about 70 times:

Code: Select all> print AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA


of course, you'll get a syntax error every time but at the end you'll get:
Code: Select allmalloc: not enough memory
lua: not enough memory

(or a reboot)


... so all tests should be done via dofile() and restart your module before if you want to get reliable results regarding later 'real world' - use!

Thomas

Re: Heap Leak on if

PostPosted: Mon Dec 01, 2014 6:07 pm
by GeoNomad
ThomasW wrote:don't rely on any memory-related tests entered directly into the commandline-interpreter
put the above code into a file and make a dofile:


Bingo! That is very helpful.

I have put my cat into a file and am updating LuaLoader to use the created function.

Code: Select allfunction cat( fname )
   file.open( fname, "r")
   while true do
      local line = file.readline()
      if (line == nil) then break end
      print(string.sub(line, 1, -2))
      end
   file.close()
end

Re: Heap Leak on if

PostPosted: Wed Dec 03, 2014 12:41 pm
by zeroday
ThomasW wrote:
GeoNomad wrote:Maybe I just don't know how to use Lua yet, but this was causing issues and I narrowed it down to a test case:

Code: Select all
NodeMcu 0.9.2 build 20141124  powered by Lua 5.1.4
> tmr.stop()
>
> if (cat == nil) then
>>    cat = 5
>>    end
> print(node.heap())
20360
>
> if (cat == nil) then
>>    cat = 5
>>    end
> print(node.heap())
19784
>
> if (cat == nil) then
>>    cat = 5
>>    end
> print(node.heap())
19056
>
> if (cat == nil) then
>>    cat = 5
>>    end
> print(node.heap())
18480
>


If I am doing something wrong, or if this has been fixed in the past week, please let me know.


Hi
just found out - don't rely on any memory-related tests entered directly into the commandline-interpreter
put the above code into a file and make a dofile:

Code: Select all> node.restart()
> �!
       �����!��1�)]��
lua: cannot open init.lua
NodeMcu 0.9.2 build 20141130  powered by Lua 5.1.4
> dofile("ifi")
20288
20248
20248
20248


The commandline seems to lack memory management completely - be patient and enter/paste the following highly sophisticated code about 70 times:

Code: Select all> print AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA


of course, you'll get a syntax error every time but at the end you'll get:
Code: Select allmalloc: not enough memory
lua: not enough memory

(or a reboot)


... so all tests should be done via dofile() and restart your module before if you want to get reliable results regarding later 'real world' - use!

Thomas


fix this "print AAA" thing in the new build 20141204