Results 1 to 12 of 12

Thread: Memory debugging

  1. #1
    Join Date
    Apr 2012
    Location
    Australia
    Posts
    1,252
    Mentioned
    1 Post(s)
    Quoted
    22 Post(s)

    Default Memory debugging

    What is the best way to call DTMs, all at the beginning and free them all upon termination or load as local integers and free at the end of the procedure?

    As a follow up to this question is there any way to get the DTMs not freed to return as a name rather than an array of integers?

    i.e.
    This
    Progress Report:
    The following DTMs were not freed: [StrangeRock, Ore, StrangeRock, Ore]

    instead of this -
    Progress Report:
    The following DTMs were not freed: [3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]


    Having some troubles working out where this memory leak is coming from, I've tried both ways of calling and freeing the DTMs but I still get a memory build up if I run the script for a long time. Fairly certain I'm freeing all DTMs that are being called.

  2. #2
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Better to load them all at the start, and free them at the end.

    Also, there is a method to name both DTMs and Bitmaps alike. The one specifically for DTMs is called SetDTMName.

    Regards,
    ~ Daniel.
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  3. #3
    Join Date
    Apr 2012
    Location
    Australia
    Posts
    1,252
    Mentioned
    1 Post(s)
    Quoted
    22 Post(s)

    Default

    Many thanks Being able to see which DTMs aren't being freed should solve this once and for all!

  4. #4
    Join Date
    Apr 2012
    Location
    Australia
    Posts
    1,252
    Mentioned
    1 Post(s)
    Quoted
    22 Post(s)

    Default

    Sorry for the double post. But, is it an issue that if you are calling a dynamic DTM with the name of the function that created it, like so:
    Simba Code:
    WaitFindDTMEx(BarDTM, x, y, MCx1, MCy1, MCx2, MCy2, 10, 1000)

    That it will need to be freed after every calling of the above code?

  5. #5
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Quote Originally Posted by P1ng View Post
    Sorry for the double post. But, is it an issue that if you are calling a dynamic DTM with the name of the function that created it, like so:
    Simba Code:
    WaitFindDTMEx(BarDTM, x, y, MCx1, MCy1, MCx2, MCy2, 10, 1000)

    That it will need to be freed after every calling of the above code?
    How does WaitFindDTMEx create a DDTM? Maybe post the script (or the part with leakages) so that we can have a better look?

  6. #6
    Join Date
    Apr 2012
    Location
    Australia
    Posts
    1,252
    Mentioned
    1 Post(s)
    Quoted
    22 Post(s)

    Default

    I had a function called BarDTM which returned an integer. That integer was the DDTM.
    Everytime I called WaitFuncEx(...) The script was re-calling the BarDTM function causing it to back-up, or so it would seem.
    I since changed that function to a procedure and declared BarDTM as a global integer for the DTM to be saved as.

    This has since fixed my memory leak

  7. #7
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Quote Originally Posted by P1ng View Post
    I had a function called BarDTM which returned an integer. That integer was the DDTM.
    Everytime I called WaitFuncEx(...) The script was re-calling the BarDTM function causing it to back-up, or so it would seem.
    I since changed that function to a procedure and declared BarDTM as a global integer for the DTM to be saved as.

    This has since fixed my memory leak
    You should only call that procedure once. For what it is doing if you call it repeatedly is that it is creating a new instance of the (D)DTM every time.
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  8. #8
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Quote Originally Posted by P1ng View Post
    I had a function called BarDTM which returned an integer. That integer was the DDTM.
    Everytime I called WaitFuncEx(...) The script was re-calling the BarDTM function causing it to back-up, or so it would seem.
    I since changed that function to a procedure and declared BarDTM as a global integer for the DTM to be saved as.

    This has since fixed my memory leak
    Yeah every time you call DTMFromString() you are (re)loading it. If you intend to use the DTM throughout the script, you should declare it globally and only call DTMFromString() once at the very start (like somewhere after SetupSRL) then free it at the very end (eg. using AddOnTerminate). There is no need to ever recall DTMFromString() as it's stored in memory until you free it.

    I still don't understand how the output from DTMFromString() is a DDTM though.

  9. #9
    Join Date
    Apr 2012
    Location
    Australia
    Posts
    1,252
    Mentioned
    1 Post(s)
    Quoted
    22 Post(s)

    Default

    Yes, so it turns out that every time I called WaitFindDTMEx(BarDTM, x, y, MCx1, MCy1, MCx2, MCy2, 10, 1000) another instance of it was created.

    Still good to know about the SetDTMName


    @Riwu - This is the code at fault, I was created a DDTM not using DTMFromString.
    Simba Code:
    function BarDTM: Integer;
    var
      dtmMainPoint: TDTMPointDef;
      dtmSubPoints: array[0..5] of TDTMPointDef;
      TempTDTM: TDTM;
     begin
      with dtmMainPoint do
      begin
        x := 293;
        y := 466;
        AreaSize := 1;
        AreaShape := 0;
        Color := Bar.Color;
        Tolerance := 45;
      end;

      with dtmSubPoints[0] do
      begin
        x := 287;
        y := 457;
        AreaSize := 1;
        AreaShape := 0;
        Color := 131072;
        Tolerance := 0;
      end;

      with dtmSubPoints[1] do
      begin
        x := 274;
        y := 469;
        AreaSize := 1;
        AreaShape := 0;
        Color := 131072;
        Tolerance := 0;
      end;

      with dtmSubPoints[2] do
      begin
        x := 286;
        y := 477;
        AreaSize := 1;
        AreaShape := 0;
        Color := 131072;
        Tolerance := 0;
      end;

      with dtmSubPoints[3] do
      begin
        x := 297;
        y := 471;
        AreaSize := 1;
        AreaShape := 0;
        Color := 131072;
        Tolerance := 0;
      end;

      with dtmSubPoints[4] do
      begin
        x:= 303;
        y := 465;
        AreaSize := 1;
        AreaShape := 0;
        Color := 131072;
        Tolerance := 0;
      end;

      with dtmSubPoints[5] do
      begin
        x:= 295;
        y := 457;
        AreaSize := 1;
        AreaShape := 0;
        Color := 131072;
        Tolerance := 0;
      end;

      TempTDTM.MainPoint := dtmMainPoint;
      TempTDTM.SubPoints := dtmSubPoints;

      Result := AddDTM(TempTDTM);
    end;

    if WaitFindDTMEx(BarDTM, x, y, MCx1, MCy1, MCx2, MCy2, 10, 1000) then  //This line kept re-calling the above function
    begin
      {$IFDEF DEBUG}
        SMART_DrawBoxEx(True, False, IntToBox(x - 25 ,y - 15, x + 25, y + 40), ClWhite);
        WriteLn('BarDDTM was found @SmithBars');
      {$ENDIF}
      Mouse(x, y, RandomRange(- 25, 25), RandomRange(- 15, 40), mouse_Left);
      {$IFDEF DEBUG}
        SMART_ClearCanvas;
      {$ENDIF}
    end;
    Last edited by P1ng; 08-13-2012 at 08:56 AM.

  10. #10
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Oh, misinterpreted what you mean, cos usually ppl dont name their DDTM creation procedure as 'BarDTM'. The common practice is to name the DDTM created (assigned by AddDTM) as 'BarDTM' rather than the procedure name (eg. here). But i guess what you did is completely fine.

  11. #11
    Join Date
    Apr 2012
    Location
    Australia
    Posts
    1,252
    Mentioned
    1 Post(s)
    Quoted
    22 Post(s)

    Default

    Yeah, it would have been completely fine if I didn't come back after a 90min run with my RAM usage through the roof :P

  12. #12
    Join Date
    Mar 2012
    Posts
    690
    Mentioned
    2 Post(s)
    Quoted
    40 Post(s)

    Default

    I load all my dtms and bitmaps at the start och the script and Free them with one procedure added in 'AddOnTerminate'.

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
  •