New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Too many levels of nested functions causes a reset #254
Comments
That is a very massive "callback hell". |
Yeah, it seems like you're running out of memory. Try your experiment again but this time print out the nesting level and the heap at each step. It should be pretty obvious then. I've been frustrated at how little memory there is for Lua scripts myself. |
NodeMCU 0.9.5 build 20150214 powered by Lua 5.1.4
lua: cannot open init.lua
> local test = function()
>> local t = function()
>> return function()
>> return function()
>> return function()
>> return function()
>> return nil
>> end
>> end
>> end
>> end
>> end
>> end
>
> test()
stdin:1: attempt to call global 'test' (a nil value)
> my result |
|
> test = function()
>> local t = function()
>> return function()
>> return function()
>> return function()
>> return function()
>> return nil
>> end
>> end
>> end
>> end
>> end
>> end
>
> test()
>
> =node.heap()
21152
> |
|
> =node.heap()
21152
> test()()()()()()
stdin:1: attempt to call a nil value
> ...... |
test()()()()()() wont work, you're not returning the "local t" function |
I can't believe the device is sow low on memory we can't afford 5 nested functions. Indeed,
This code, when loaded, prints 15 (correctly), proving that compilation, and execution, succeeds, but NodeMCU restarts a second or so after. The actual issue is some bug in the compiler (node.compile() fails similarily). This might be a memory management issue, but I don't think it's a memory outage. |
JFYI, the problem doesn't appear (at least on 5 nesting levels;) ) on current dev096 firmware:
|
@szakharchenko, These are known constraints of running a Lua RTS on a chip with 40kB working RAM whee a chunk is taken up by the firmware. Compiling is very malloc/free hungry and fragments the memory pool. Avoiding compilation in general results in more usable memory; again a known characteristic. Sorry but this isn't an issue in the sense of something that we can identify a specific fix for. |
Hi,
I'm not sure if this is fixable or simply a memory limitation (I assume the interpreter is running out of heap at some point) but I figured this was worth sharing since it took me a long time to track down this issue in a real program.
This appears to be a regression between master and dev / dev096 btw, the level of nesting I was using in my real code still works if I flash back to the master branch.
Here is a silly test case to show the issue:
trying to execute this (or even trying to node.compile() it) will cause a reboot. Removing a level of nesting makes the issue disappear.
The text was updated successfully, but these errors were encountered: