Closed Quenty closed 10 years ago
This has to do with Roblox not collecting dead Lua threads. I've also noticed this when using Delay-intensive scripts in Script Builders.
Yeah, also threads are just resource intensive. I switched from a thread to queue based system in a script and went from 58% activity to 14% activity.
This can be achieved with a single loop. Here is some code which better illustrates the point:
while true do
Spawn(function() print("new thread") end)
end
print("old thread")
Sample output:
old thread
new thread
new thread
...
The fact that old thread
is always printed first indicates that calling a function such as Spawn
and Delay
will not cause the calling thread to yield. This means the spawned threads have no chance to execute and get garbage collected until you are done looping. If you want the new threads to start running, you should put a wait inside the loop:
while true do
Spawn(function() print("new thread") end)
wait()
end
In short, this "bug" is simply a misunderstanding of how RBX.Lua threads work and is not anything that needs to be fixed.
The following code creates a memory leak in a player's game, if ran local, that memory leaks and uses up their core's memory unless they've limited Lua's memory.
Unlike most crash scripts, this can actually crash a single core computer, as Mark Otaris can testify.