Page 2 of 2 FirstFirst 12
Results 26 to 36 of 36

Thread: How to Free DTM/Bitmap's the correct way

  1. #26
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,074
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    Quote Originally Posted by Pakyakkistan View Post
    This may be considered grave digging, but seeing as its a tutorial and is meant to be a learning reference; you should probably mention that you need to declare those DTMs as global variables as well. If you don't, and try declaring them as variables in each procedure you search for them, you won't ever find the DTMs because it will try to declare them as 'new' variables in each procedure. Other then that, wonderful guide! Glad it was here so I ensured I was doing it right.

    Edit: Also, if you are going to continue calling for the DTMs, you'll need to Load and Free them within the 'main' loop. Or else you'll free them and gt a run-time error because you won't have any DTMs loaded.
    Thats more of a subject for DTM tutorial, rather then how to free resources properly. But yes, each of your point is valid.
    There used to be something meaningful here.

  2. #27
    Join Date
    Jan 2012
    Location
    Long Island, NY
    Posts
    413
    Mentioned
    5 Post(s)
    Quoted
    95 Post(s)

    Default

    Quote Originally Posted by Pakyakkistan View Post
    Edit: Also, if you are going to continue calling for the DTMs, you'll need to Load and Free them within the 'main' loop. Or else you'll free them and gt a run-time error because you won't have any DTMs loaded.
    Shouldn't you just load the DTMs before your main loop once and free them once you terminate the script. What's the point of constantly loading and unloading them?

  3. #28
    Join Date
    Aug 2012
    Location
    The Dark Tower
    Posts
    154
    Mentioned
    5 Post(s)
    Quoted
    56 Post(s)

    Default

    Quote Originally Posted by Zeta Matt View Post
    Read this: http://docs.villavu.com/simba/script...m.html#freedtm
    Called DTM's stay on your computer's memory. If many DTM's are piled in it, it will suffer of memory leaking, basicaly... That's why you have to free them.
    Quote Originally Posted by Brotein View Post
    Shouldn't you just load the DTMs before your main loop once and free them once you terminate the script. What's the point of constantly loading and unloading them?
    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

  4. #29
    Join Date
    Jan 2012
    Location
    Long Island, NY
    Posts
    413
    Mentioned
    5 Post(s)
    Quoted
    95 Post(s)

    Default

    Quote Originally Posted by Pakyakkistan View Post
    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.

  5. #30
    Join Date
    Feb 2013
    Location
    Narnia
    Posts
    615
    Mentioned
    8 Post(s)
    Quoted
    252 Post(s)

    Default

    Quote Originally Posted by Brotein View Post
    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.
    thats how i do it and thats how i learned in a dtm tut, never had a script bog down or cpu shoot up

    View my OSR Script Repository!


    Botted to max
    Guides: How to Report Bugs to the Scripter
    ~~~~ Moved to Java. Currently Lurking ~~~~

  6. #31
    Join Date
    Aug 2012
    Location
    The Dark Tower
    Posts
    154
    Mentioned
    5 Post(s)
    Quoted
    56 Post(s)

    Default

    Quote Originally Posted by Brotein View Post
    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.
    Makes sense. Didn't know, never globally declared or free'd my DTMs. This is the only global DTM tut i've looked at, thanks everyone for the pointers.

  7. #32
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,283
    Mentioned
    105 Post(s)
    Quoted
    489 Post(s)

    Default

    Quote Originally Posted by Sir Ducksworthy View Post
    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.[/I][/B]
    All DTMs are freed when the script crashed or is stopped.

  8. #33
    Join Date
    Aug 2012
    Location
    The Dark Tower
    Posts
    154
    Mentioned
    5 Post(s)
    Quoted
    56 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    All DTMs are freed when the script crashed or is stopped.
    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'.

  9. #34
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,283
    Mentioned
    105 Post(s)
    Quoted
    489 Post(s)

    Default

    Quote Originally Posted by Pakyakkistan View Post
    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'.
    Even without the add on terminate, simba will always free them. Filling your memory can only happen while the script is running.

  10. #35
    Join Date
    Aug 2012
    Location
    The Dark Tower
    Posts
    154
    Mentioned
    5 Post(s)
    Quoted
    56 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    Even without the add on terminate, simba will always free them. Filling your memory can only happen while the script is running.
    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.

  11. #36
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,283
    Mentioned
    105 Post(s)
    Quoted
    489 Post(s)

    Default

    Quote Originally Posted by Pakyakkistan View Post
    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.

Page 2 of 2 FirstFirst 12

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •