Signup Now
Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12
  1. #11
    Free User Orimorfus's Avatar
    Join Date
    Dec 2013
    Location
    Way to Deletera
    Posts
    314
    Reputation
    92
    Rep Power
    21
    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 ?

  2. #12
    Moderator Josh's Avatar
    Join Date
    Dec 2013
    Posts
    1,395
    Reputation
    183
    Rep Power
    24
    Quote Originally Posted by Orimorfus View Post
    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

    Code:
    0001 contains 0101 (4)
    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)
    0002 contains 0101 (4)
    Then, theNumber has 1 added to it, and you get

    Code:
    0001 contains 0101 (4)
    0002 contains 0110 (5)
    Then the assignment is performed to a

    Code:
    0001 contains 0110 (5)
    0002 contains 0110 (5)
    At this point, the calling convention, language, or garbage collection details how the second instance of the value is deleted...

    In other circumstances, it will work so you start again with

    Code:
    0001 contains 0101 (4)
    Then, when the function is called, you'll get this:

    Code:
    0001 contains 0101 (4)
    0002 contains 0001 (0001 being the address of the variable we want to add to)
    Next, 1 is added to the number:

    Code:
    0001 contains 0110 (5)
    0002 contains 0001
    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.

    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.

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •