Assumed that not calling them would cause a stack of DTMs. I know that doing this without globally doing it would cause this. Each time you load that DTM it would add up.
Edit: For example, my Iron Knife smither, remove some of the FreeDTM procedures and watch the DTM amounts stack when you stop the script. But, like I said, I have no idea if its the same thing when you globally declare them
Why wouldn't you just declare them globally and only load them once?
Simba Code:program new;
var
DTM1, DTM2, DTM3 : Integer;
procedure setDTMs;
begin
DTM1 := DTMFromString('');
DTM2 := DTMFromString('');
DTM3 := DTMFromString('');
end;
procedure killDTMs;
begin
freeDTMs([DTM1, DTM2, DTM3]);
end;
begin
setDTMs;
addOnTerminate('killDTMs');
repeat
//do our stuff
until (not isLoggedIn);
killDTMs;
terminateScript;
end.
I can use those DTMs in any function or procedure and I only need to load them once, and free them once.
View my OSR Script Repository!
Botted to max
Guides: How to Report Bugs to the Scripter
~~~~ Moved to Java. Currently Lurking ~~~~
Yea, I wasn't paying attention either. Since you have AddOnTerminate there truly isn't a need to free your DTMs in the loop repeatedly. As long as you have them freed on termination; my bad @Brotein; - Thanks tho
Was thinking that they are filling memory as long as they are being 'used'.
Wait what?
You're saying that if I stop the script midway it should free my DTMs? I thought this was why you added it on terminate because it wouldn't free them?
Or are you saying that they are freed once the script is ended? Sorry for my confusion, just wanting to make sure I understand correctly.
Let me explain you a bit how simba handles bitmaps and dtms. When you create a DTM or Bitmap(resource from this moment on) with most of the common used functions, you will get an integer instead of a TMufasaBitmap or TDTM. This integer is not a pointer, nor is it the resource itself(obviously ). Simba manages a list(array) with all the DTMs and a list with all the bitmaps. The integer you get returned is simply the index/place in the array where the resource is stored.
When the script threads end either by being stopped or crashing, simba will free all the bitmaps and dtms it still has in those lists. So it will not cause memory leaks. When this happens simba will display a line you are probably familiar with. ("DTMs not freed..")
So when does freeing actually matter? Assume the following code is used:
Simba Code:repeat
wait(50);
bankersDTM := DTMFromString('avraagaregarega');
until(FindDTM(bankersDTM )); //arrived at bank
FreeDTM(bankersDTM);
If the script continues to run this code the memory will be filled with the same DTM of the bankers... Only the last one is freed. I actually see this happen every now and then.
Last edited by masterBB; 03-21-2014 at 05:36 PM.
Working on: Tithe Farmer
There are currently 1 users browsing this thread. (0 members and 1 guests)