You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Doing iterative string building like this can lead to issues.
local n = 9
for i=1,n do
local s = ""
for i=1,(2^i) do
s = s.."!"
end
end
For n = 9, this is fine, but n = 10 appears to hang something in the firmware. LEDs will hold their state, diii continues to show as connected, but all code execution seems to stop. Soft reboot via ^^r doesn't work, but physically reconnecting seems to fix things.
Interesting to note that building one constant string of size 2^10 does not cause the same behavior. Maybe the strings spawned by concatenation are not garbage collected fast enough and cause an out-of-memory failure because of it?
EDIT: Quick calc using the summation formula would mean n=9 => 131,238B and n=10 => 524,800B assuming nothing gets free'd before the end of the loop. n=10 would be more than available SRAM of the Pico 2.
EDIT 2: Yeah, I think garbage collection is the issue. Adding collectgarbage("collect") to the inner for-loop fixes the crash. I don't think this allocation/collection problem is realistically something to fix, but would be nice to keep the Lua environment running if possible.
The text was updated successfully, but these errors were encountered:
i need to do some real benchmarking of the memory limits within this system. will see if i can put in some introspection utilities for better understanding what's going on.
heap has about 220k so i think your assessment makes sense!
i'll update the README to indicate the memory limitations. let me know if you'd like this issue reopened, if there is a proposal for a structural change.
Doing iterative string building like this can lead to issues.
For
n = 9
, this is fine, butn = 10
appears to hang something in the firmware. LEDs will hold their state,diii
continues to show as connected, but all code execution seems to stop. Soft reboot via^^r
doesn't work, but physically reconnecting seems to fix things.Interesting to note that building one constant string of size 2^10 does not cause the same behavior. Maybe the strings spawned by concatenation are not garbage collected fast enough and cause an out-of-memory failure because of it?
EDIT: Quick calc using the summation formula would mean
n=9 => 131,238B
andn=10 => 524,800B
assuming nothing gets free'd before the end of the loop.n=10
would be more than available SRAM of the Pico 2.EDIT 2: Yeah, I think garbage collection is the issue. Adding
collectgarbage("collect")
to the inner for-loop fixes the crash. I don't think this allocation/collection problem is realistically something to fix, but would be nice to keep the Lua environment running if possible.The text was updated successfully, but these errors were encountered: