1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

HUGE RAM Usage when executing this script

Discussion in 'Scripting Workshop' started by rossc, Dec 18, 2021.

  1. rossc

    rossc New Member

    Messages:
    9
    Hi guys,

    Sorry to have to post again but, in an attempt to solve the issue seen in my previous post, I've come across some really strange behaviour when executing this seemingly simple script. I'm simply incrementing a counter after a wait statement, until the counter reaches 20,000,000 (number of microseconds in 20 seconds).

    As soon as I press a note, triggering the incrementation of the counter, my RAM usage for Kontakt climbs to about 16GB!

    Surely I'm reassigning the value for a single variable, not instantiating anything new, how am I using so much memory?

    Thanks!

    Code:
    Code:
    on note
    
        $counter := 0
    
        while ($counter <= 20000000)
    
            message($counter)
            wait(1)
            inc($counter)
    
        end while
    
    end on
     
  2. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Hmmmm, I cannot confirm any RAM usage bump, but it DOES take up a lot of CPU. wait(1) is not very efficient. Why would you need to do this?

    EDIT: Ah, I saw your other thread. You should look into using the listener callback for timed stuff like this :)
     
  3. rossc

    rossc New Member

    Messages:
    9
    Ah of course, the listener callback makes sense, I hadn't thought of that. My initial idea was to run through 0 - 20,000,000, incrementing every microsecond, then play my samples at the appropriate time by checking the counter value, while also updating my playhead slider at the appropriate time, meaning everything was happening in the same loop.

    Not sure why I get the RAM usage issue with this solution. Perhaps as bug? I'll give the listener method a shot :)
     
  4. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Yeah that is way overkill. You don't need microsecond precision here, I am pretty sure :)