I guess this can be due to poorly written loops, happens preety often when i try to test something (obviously cause i suck at lua), windbot can even take 99% od your cpu preety easy, im not sure but didnt windbot use to break such loops on its own ?
I guess this can be due to poorly written loops, happens preety often when i try to test something (obviously cause i suck at lua), windbot can even take 99% od your cpu preety easy, im not sure but didnt windbot use to break such loops on its own ?
The only person who would really know how WindBot handles garbage collection is Lucas, but in reality, garbage collection is handled for Lua by the engine itself, see this page, search 2.10 - Garbage Collection.
I know in Java it's possible to cause a memory leak using global references to instantiated objects, but I don't believe this is possible in Lua since the engine works by replicating data as opposed to referencing it, that is to say if you do:
function addOne(theNumber)
return theNumber + 1
end
a = 5
addOne(a)
In this code, in Java / C++ / C#, depending on the calling convention and how the code is adapted, it might maintain 2 copies of the data, or only one. It also depends on optimisation, so you could end up the following memory structure
0001 is the location in memory of the variable a, which contains the number 5 (binary form: 0101). When you call addOne, the following happens:Code:0001 contains 0101 (4)
Then, theNumber has 1 added to it, and you getCode:0001 contains 0101 (4) 0002 contains 0101 (4)
Then the assignment is performed to aCode:0001 contains 0101 (4) 0002 contains 0110 (5)
At this point, the calling convention, language, or garbage collection details how the second instance of the value is deleted...Code:0001 contains 0110 (5) 0002 contains 0110 (5)
In other circumstances, it will work so you start again with
Then, when the function is called, you'll get this:Code:0001 contains 0101 (4)
Next, 1 is added to the number:Code:0001 contains 0101 (4) 0002 contains 0001 (0001 being the address of the variable we want to add to)
At this point, the information stored at 0002 should be deleted, but as above, it depends on the calling convention, the language, and how the code itself is written. Anyway, the Lua engine handles things at this level, so it should, theoretically, be impossible to enter a scenario where that "pointer" (0002 in the last code block) is not deleted.Code:0001 contains 0110 (5) 0002 contains 0001
In the case of Lua C++ integration, the first example is how it works (I think, 99% sure). It may be optimised out when compiled, and it could work the other way around at a core level, but either way the point is that all this logic is executed by the Lua engine, and not by Lucas' code or by the script itself. I can't remember exactly where I was going with this....
Last edited by Josh; 06-03-2016 at 11:46 PM.