How to Free DTM/Bitmap's the correct way
Introduction:
Basically in this guide I am going to teach you about a function called AddonTerminate(), what it is and how to use it.
Okay, so we have our two procedures...
Firstly our procedure to Load our DTM/Bitmap's and secondly our procedure to Free them.
Example for DTM's:
Simba Code:procedure DTMZ;
begin
Dust:= DTMFromString('mbQAAAHicY2VgYMhiYmBIAuJCJgg7B4ifM0DwMyB+A8SPgDjUUBpIMqFgfgZMwIgFgwEAV7cHYg==');
Choc:= DTMFromString('mbQAAAHicY2VgYMhhYmAoBOJUIE4H4jIgfgQUvwPEr4D4PhA/AWIfHQkgyYSC+RkwASMWDAYAUOoHRg==');
end;
procedure FREEDTMZ;
begin
FreeDtm(Dust);
FreeDTM(Choc);
end;
Now most people usually free them using:
Simba Code:begin
SetupSRL;
DTMZ;
repeat
CrushProcess;
if(Crushes+1>Howmany)then
begin
FREEDTMZ;
terminatescript();
end;
until (not Loggedin);
end.
The Problem with using that method or using this method:
Simba Code:begin
SetupSRL;
DTMZ;
repeat
CrushProcess;
until (not Loggedin);
FREEDTMZ;
terminatescript();
end.
Is that if the script messes up and is stuck in a loop or what not, chances are your not going to be logged out because it will keep you logged in by continuously interacting with the Rs client.
You will then terminate it manually with the Stop button on Simba
Which will unfortunately leave you with Non Freed Dtm/Bitmap's
This causes excess memory usage on your computer and ultimately slows down Scripts/Simba.
To avoid this we simply need to use the function:
Simba Code:Addonterminate();
What this function does is it allows you to call any procedure before the script is terminated.
How do we do this?
We need to call it in our Setup in the Main Loop
For our FREEDTMZ; procedure it would look something like this:
Simba Code:begin
SetupSRL;
DTMZ;
Addonterminate('FREEDTMZ');
repeat
CrushProcess;
until (not Loggedin);
FREEDTMZ;
terminatescript();
end.
Congratulation's! you just saved your computer's memory
You'll notice now no matter how you stop your script all the Dtm/Bitmap's will be freed