Page 1 of 2 12 LastLast
Results 1 to 25 of 36

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

  1. #1
    Join Date
    Jul 2008
    Location
    NSW, Australia
    Posts
    881
    Mentioned
    0 Post(s)
    Quoted
    3 Post(s)

    Talking How to Free DTM/Bitmap's the correct way

    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
    Last edited by Sir Ducksworthy; 03-26-2012 at 08:25 PM.

  2. #2
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    1,199
    Mentioned
    0 Post(s)
    Quoted
    26 Post(s)

    Default

    Well this is actually really useful and I can't believe no one has ever posted on here. On the few basic things I had used I always loaded the DTM's in the same procedure and freed them at the end of the procedure. It worked sometimes, but if you stop the script in the middle of the procedure your DTM's wouldn't be freed. This will be useful to know/use!

  3. #3
    Join Date
    Feb 2012
    Location
    Somewhere, over the rainbow...
    Posts
    2,272
    Mentioned
    3 Post(s)
    Quoted
    45 Post(s)

    Default

    Thanks for bumping Hazzah

    OT: I always use this method and had to idea there was a tutorial on it. Good work leet.

    +rep

  4. #4
    Join Date
    May 2012
    Location
    UK
    Posts
    85
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks I found this very useful...should be near the top it is important !

  5. #5
    Join Date
    Jun 2012
    Posts
    4,867
    Mentioned
    74 Post(s)
    Quoted
    1663 Post(s)

    Default

    You should link this in your signature if you have room

  6. #6
    Join Date
    Jan 2012
    Location
    127.0.0.1
    Posts
    702
    Mentioned
    11 Post(s)
    Quoted
    76 Post(s)

  7. #7
    Join Date
    Nov 2008
    Location
    UK
    Posts
    153
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    This has been a great help for my current script. Been getting a lot of unfreed DTMs when the script was stopped. This simple fix has now solved that.

  8. #8
    Join Date
    Feb 2010
    Location
    Somewhere on earth
    Posts
    56
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    SRL has a free procedure too FreeSRL;

  9. #9
    Join Date
    Nov 2012
    Posts
    2,351
    Mentioned
    55 Post(s)
    Quoted
    603 Post(s)

    Default

    Is it just me or is this not working too gret when you have like 50 DTMs? Atleast a few seem to not get freed


    Programming is like trying keep a wall of shifting sand up, you fix one thing but somewhere else starts crumbling

  10. #10
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,072
    Mentioned
    296 Post(s)
    Quoted
    1094 Post(s)

    Default

    50 dtms.... what the..

  11. #11
    Join Date
    Jun 2012
    Posts
    4,867
    Mentioned
    74 Post(s)
    Quoted
    1663 Post(s)

    Default

    Quote Originally Posted by Ollybest View Post
    50 dtms.... what the..
    Probably for his AIO bow fletcher.

  12. #12
    Join Date
    Mar 2013
    Posts
    58
    Mentioned
    0 Post(s)
    Quoted
    24 Post(s)

    Default

    Call me stupid, I still don't know how to free...

  13. #13
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    Quote Originally Posted by heyaiam View Post
    Call me stupid, I still don't know how to free...
    Building off the original post:

    Simba Code:
    // the DTM declared globally:
    var
      someDTM: Integer;

    // the DTM being setup for global use.
    procedure SetupGlobals();
    begin
      someDTM := DTMFromString('the actual string goes here');
    end;

    // call this function when the script stops (best used with a call shown later, AddOnTerminate)
    procedure FreeGlobals();
    begin
      FreeDTM(someDTM);
    end;

    // main code in script to be used:
    begin
      SetupGlobals(); // setups the DTM to use
      AddOnTerminate('FreeGlobals'); // calls this function when the script stops (ex - it will free the DTM for us)
    end.

    Something like the above is a basic example/variation of what the original poster is saying. (Note this code was all typed in the browser and not compiled for test)

  14. #14
    Join Date
    Mar 2013
    Posts
    58
    Mentioned
    0 Post(s)
    Quoted
    24 Post(s)

    Default

    Where do I put in? like what line and stuff? assuming I already have the script open? I'm really noob at this. .

  15. #15
    Join Date
    Mar 2013
    Posts
    58
    Mentioned
    0 Post(s)
    Quoted
    24 Post(s)

    Default

    I hav no idea how to free :S
    Please help! !

  16. #16
    Join Date
    Mar 2007
    Posts
    393
    Mentioned
    1 Post(s)
    Quoted
    98 Post(s)

    Default

    Quote Originally Posted by heyaiam View Post
    I hav no idea how to free :S
    Please help! !
    after you have found your DTM add line:
    Simba Code:
    freeDTM(DTMname);

  17. #17
    Join Date
    Mar 2013
    Posts
    58
    Mentioned
    0 Post(s)
    Quoted
    24 Post(s)

    Default

    Quote Originally Posted by t4q View Post
    after you have found your DTM add line:
    Simba Code:
    freeDTM(DTMname);
    Sorry I don't quite understand what you mean by this.
    I can't find anything with DTM in the scripts I wish to run.

  18. #18
    Join Date
    Dec 2011
    Location
    Holland
    Posts
    545
    Mentioned
    0 Post(s)
    Quoted
    19 Post(s)

    Default

    Nice guide, I've used this aswell and it's really handy.

    Though you say: "You'll notice now no matter how you stop your script all the Dtm/Bitmap's will be freed"

    CHALLENGE ACCEPTED

    - run this:
    Simba Code:
    var
      s: string;

    begin
      DTMZ;
      Addonterminate('FREEDTMZ');
      s := s[0];
    end.

    That's how I stop my script

  19. #19
    Join Date
    Aug 2013
    Posts
    35
    Mentioned
    0 Post(s)
    Quoted
    16 Post(s)

    Default

    What's the point of freeing stuff on terminate ,when Simba does it for you?

  20. #20
    Join Date
    May 2012
    Location
    Brazil, Rio de Janeiro.
    Posts
    160
    Mentioned
    2 Post(s)
    Quoted
    32 Post(s)

    Default

    Quote Originally Posted by bgtemp View Post
    What's the point of freeing stuff on terminate ,when Simba does it for you?
    ^ I also got this question :O But this is not my main point.

    Also, if the point is to prevent memory leaking, this function would work only on scripts with few DTM/BitMaps being called, right? I mean, if 100 DTM's and BitMaps are called along a script and you only free them on terminate... it would cause a memory leak anyway, wouldn't it?
    "If, at someone, your wound still arouses pity,
    stone this vile hand that strokes you,
    spit on this lips that kiss you." (Augusto dos Anjos, translated from brazillian portuguese to english)
    http://villavu.com/forum/image.php?type=sigpic&userid=96295&dateline=137947  1136

  21. #21
    Join Date
    May 2012
    Location
    Brazil, Rio de Janeiro.
    Posts
    160
    Mentioned
    2 Post(s)
    Quoted
    32 Post(s)

    Default

    Quote Originally Posted by heyaiam View Post
    Sorry I don't quite understand what you mean by this.
    I can't find anything with DTM in the scripts I wish to run.
    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.
    "If, at someone, your wound still arouses pity,
    stone this vile hand that strokes you,
    spit on this lips that kiss you." (Augusto dos Anjos, translated from brazillian portuguese to english)
    http://villavu.com/forum/image.php?type=sigpic&userid=96295&dateline=137947  1136

  22. #22
    Join Date
    Aug 2013
    Posts
    35
    Mentioned
    0 Post(s)
    Quoted
    16 Post(s)

    Default

    Quote Originally Posted by archermaths View Post
    ^ I also got this question :O But this is not my main point.

    Also, if the point is to prevent memory leaking, this function would work only on scripts with few DTM/BitMaps being called, right? I mean, if 100 DTM's and BitMaps are called along a script and you only free them on terminate... it would cause a memory leak anyway, wouldn't it?
    No, it would only build memory stack. "Leak" is when you lose access to memory region. All those 100 Bitmaps would be freed on terminate , if there were a leak they would remain after script is done ,until you close Simba.

  23. #23
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default

    Tend to use:

    Simba Code:
    function TryFreeDTM(DTM : Integer) : Boolean;
    begin
      try
        FreeDTM(DTM);
      except
      finally
      end;
    end;

    Do the same for Bitmaps.

  24. #24
    Join Date
    May 2012
    Location
    Brazil, Rio de Janeiro.
    Posts
    160
    Mentioned
    2 Post(s)
    Quoted
    32 Post(s)

    Default

    Quote Originally Posted by bgtemp View Post
    No, it would only build memory stack. "Leak" is when you lose access to memory region. All those 100 Bitmaps would be freed on terminate , if there were a leak they would remain after script is done ,until you close Simba.
    Makes sense... Anyway, it would be useless to free on terminate, then...?
    "If, at someone, your wound still arouses pity,
    stone this vile hand that strokes you,
    spit on this lips that kiss you." (Augusto dos Anjos, translated from brazillian portuguese to english)
    http://villavu.com/forum/image.php?type=sigpic&userid=96295&dateline=137947  1136

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

    Default

    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.

Page 1 of 2 12 LastLast

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
  •