Memory leaks in scripts
Posted: 02 Dec 2024, 16:59
Well, I'm crazy excited because after 12(or more?) years of building my wkp in Usine, it is finally doing what I envisioned at the beginning. Thanks to Olivier et al for making this amazing software, thanks especially for Usine objects, and VST loadFromFileDirect which were both total game-changers for me!
So I have this marvellously debugged wkp doing exactly what I want, with one problem. When I transfer my wkp to my gig computer, it loads up all wrong, turns off a bunch of midi interfaces, and crashes the first time I try to load a file.
I understand now that this is because of memory leaks, and I'm trying to go through all my scripts looking for issues. The one thing that Olivier has mentioned is running off the end of an array. But I do not know what other practices might be a problem, and any further information on this would be welcome.
I will start off with a function that I imagine is an issue. I am paging through this list, but it looks like since I may remove an item partway through the process, I could try to address an element beyond the end of the list. Is this correct? I assume that the function does not stop as soon as it gets to the result line. If not, maybe this is fine. It still seems like bad form, so I am going to rewrite it:
I was hoping if anybody else has experienced these types of problems, they could post examples of their issues here... it is obviously a crucial part of script writing for Usine. As I find more, I will do so as well.
THANKS ALL!
=eric
So I have this marvellously debugged wkp doing exactly what I want, with one problem. When I transfer my wkp to my gig computer, it loads up all wrong, turns off a bunch of midi interfaces, and crashes the first time I try to load a file.
I understand now that this is because of memory leaks, and I'm trying to go through all my scripts looking for issues. The one thing that Olivier has mentioned is running off the end of an array. But I do not know what other practices might be a problem, and any further information on this would be welcome.
I will start off with a function that I imagine is an issue. I am paging through this list, but it looks like since I may remove an item partway through the process, I could try to address an element beyond the end of the list. Is this correct? I assume that the function does not stop as soon as it gets to the result line. If not, maybe this is fine. It still seems like bad form, so I am going to rewrite it:
Code: Select all
//// returns the data associated with a tag,
//// and removes the line containing the tag from the list
function CutLineForTag(TAG: string; list: tStringlist): string;
var line: string;
var i: integer;
begin
for i := 0 to (list.count - 1) do
begin
//debug('checking line:' + intToStr(i) + ': ' + list.getStrings(i));
line := list.getStrings(i);
if stringsMatch(TAG, getTagForLine(line)) then
begin
result := getDataForLine(line);
list.delete(i);
debug('stripped ' + tag + ', value: ' + getDataForLine(line));
end;
end;
end;THANKS ALL!
=eric