View Single Post
Old 24th February 2017, 12:22   #14  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by spoRv View Post
Once I had a memory leak problem usinga a function with Gscriptclip inside, and some current_frame instances, that lead always to "out of memory, folks" message... I tried your workaround but, albeit working, it didn't stop crashes...

Then, I followed another, maybe unhortodox, path, and strangely it worked - still don't know why!
Interesting.
Regarding string table memory use, there is no difference between your 'before' and 'after' variants - the total run-time script size is effectively the same - so I don't understand why one should work and not the other.

But I note that there is a potential problem with your use of global variables (in both versions).
If any of the functions is called more than once (with different parameter values), the run-time scripts for all except the last invocation of the function will see the wrong value for the global.
This is because all the assignments to the global occur at compile-time, before any of the run-time scripts are evaluated, and so the run-time script for each invocation of the function sees only the final value of the global.
(See The script execution model/Scope and lifetime of variables)

For example, with
Code:
function x(clip clip, int parameter) {
global parameter=parameter
ScriptClip(clip, """
  ...
""")
}
...
x(1)
...
x(2)
when the run-time script for x(1) is evaluated, parameter has the value 2, not 1.

That's why GRunT (GScriptClip, etc) introduced the args parameter to 'freeze' compile-time values into a run-time script - the problem above is solved by writing
Code:
function x(clip clip, int parameter) {
# global parameter=parameter : removed
Gscriptclip(clip, """
  ...
""", args="parameter")
}
Although this problem is the same in both the 'before' and 'after' outlines you showed, I wonder if perhaps some subtle difference in the way the globals were used in the actual script was the cause of the change in behaviour. (But if no function was actually called more than once, this issue can be ruled out.)
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote