Page 4 of 4 FirstFirst ... 234
Results 76 to 87 of 87

Thread: What can cause a memory leak?

  1. #76
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Freeing the form frees all it's components/children.

  2. #77
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Woah! What could possibly be causing an increase of memory use THAT much in object tracking?
    I'm surprised..

  3. #78
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Forget everything I said in the above posts, I found the problem, and it's not with MSI. It's with paintsmart.scar. I added writeln's to all the try..except statements in the paintsmart.scar functions, and none were being freed.
    Progress Report:
    [0:00:17]: SMART BITMAP NOT FREED
    [0:00:17]: SMART BITMAP NOT FREED
    [0:00:17]: SMART BITMAP NOT FREED
    [0:00:17]: SMART BITMAP NOT FREED
    [0:00:17]: SMART BITMAP NOT FREED
    [0:00:17]: SMART BITMAP NOT FREED
    [0:00:17]: SMART BITMAP NOT FREED
    [0:00:17]: SMART BITMAP NOT FREED
    [0:00:17]: SMART BITMAP NOT FREED
    I'm surprised I didn't think of this earlier. Guess no one put together to dots. Now how to fix it..

    The functions call FreeBitmap(drawing) and drawing is a TBitmap, so I changed all the FreeBitmaps to drawing.free and it got rid of the error, but nothing gets painted on SMART, so some edits will have to be made. The important thing is the issue has been found.

  4. #79
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Yes! Good job
    Hopefully this will get rid of most of the memory leaks

  5. #80
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    Simba Code:
    //-----------------------------------------------------------------//
    //--               Scar Standard Resource Library                --//
    //--               � Smart Painting routines                     --//
    //-----------------------------------------------------------------//
    // procedure ClearCanvas(Canvas: TCanvas; W, H: integer);          //
    // procedure ClearRSCanvas(canvas: TCanvas);                       //
    // procedure DrawDotsEx(Clear: boolean; Pixels: T2DPointArray);    //
    // procedure SMART_DrawDotsEx(Clear: boolean; pixels: TPointArray; color: TColor); //
    // procedure SMART_DrawDots(Dots: TPointArray);                    //
    // procedure SMART_DrawBoxEx(Clear: boolean; Box: TBox; color: TColor); //
    // procedure SMART_DrawBox(Box: TBox);                             //
    // procedure SMART_DrawTextEx(Clear: Boolean; X, Y: Integer; Font, Text: string; Color: TColor); //
    // procedure SMART_DrawText(X, Y: Integer; Font, Text: string; Color: TColor); //
    //-----------------------------------------------------------------//

    {*******************************************************************************
    procedure ClearCanvas(Canvas: TCanvas; W, H: integer);
    Contributors: Sir R. Magician, mastaraymond
    Description: Clears a canvas of dimensions (w, h)
    *******************************************************************************}

    procedure ClearCanvas(Canvas: TCanvas; W, H: integer);
    var
      CleanBMP: integer;
    begin
      try
        try
          CleanBMP := BitmapFromString(W, H, '');
         {$IFNDEF SIMBA}Safe{$ENDIF}DrawBitmap(CleanBMP, Canvas, 0, 0);
        finally
          FreeBitmap(CleanBMP);
        end;
      except
        WriteLn(ExceptionToString(ExceptionType, ExceptionParam));
      end;
    end;

    {*******************************************************************************
    procedure ClearRSCanvas(Canvas: TCanvas);
    Contributors: Sir R. Magician
    Description: Clears a canvas of RS dimensions
    *******************************************************************************}

    procedure ClearRSCanvas(Canvas: TCanvas);
    begin
      ClearCanvas(Canvas, MIX2 + 100, MIY2 + 100);
    end;

    {*******************************************************************************
    procedure DrawDotsEx(Clear: boolean; Pixels: T2DPointArray);
    Contributors: Sir R. Magician
    Description: Draws an ATPA onto the SMART Debug canvas
    *******************************************************************************}

    procedure DrawDotsEx(Clear: boolean; Pixels: T2DPointArray);
    {$IFDEF SMART}
    var
      I, J, H, K, Color: integer;
    begin
      with TBitmap.Create do
        try
          try
            Canvas.Handle := SmartGetDebugDC;
           
            if (Clear) then
              ClearRSCanvas(Canvas);
           
            H := High(Pixels);
            for I := 0 to H do
            begin
              Color := I div 5 + I mod 5;
              case Color of
                0: Canvas.Pen.Color := clWhite;
                1: Canvas.Pen.Color := clYellow;
                2: Canvas.Pen.Color := clBlue;
                3: Canvas.Pen.Color := clLime;
                4: Canvas.Pen.Color := clGreen;
              end;
             
              K := High(Pixels[I]);
              for J := 0 to K do
              begin
                Canvas.MoveTo(Pixels[I][J].x - 1, Pixels[I][J].y);
                Canvas.LineTo(Pixels[I][J].x, Pixels[I][J].y);
              end;
            end;
          except
            WriteLn(ExceptionToString(ExceptionType, ExceptionParam));
          end;
        finally
          Free;
        end;
    {$ELSE}
    begin
    {$ENDIF}
    end;

    {*******************************************************************************
    procedure SMART_DrawDotsEx(Clear: boolean; Pixels: TPointArray; Color: TColor);
    Contributors: Sir R. Magician, caused, mastaraymond
    Description: Draws a TPA onto the SMART Debug canvas
    *******************************************************************************}

    procedure SMART_DrawDotsEx(Clear: boolean; Pixels: TPointArray; Color: TColor);
    {$IFDEF SMART}
    var
      I, H: integer;
    begin
      with TBitmap.Create do
        try
          try
            Canvas.Handle := SmartGetDebugDC;
            Canvas.Pen.Color := Color;
           
            if (Clear) then
              ClearRSCanvas(Canvas);
           
            H := High(Pixels);
            for I := 0 to H do
            begin        
              Canvas.MoveTo(Pixels[I].x - 1, Pixels[I].y);
              Canvas.LineTo(Pixels[I].x, Pixels[I].y);
            end;
          except
            WriteLn(ExceptionToString(ExceptionType, ExceptionParam));
          end;
        finally
          Free;
        end;
    {$ELSE}
    begin
    {$ENDIF}
    end;

    {*******************************************************************************
    Procedure SMART_DrawDots(Dots: TPointArray);
    Contributors: Sir R. Magician
    Description: Draws a TPA onto the SMART Debug canvas
    *******************************************************************************}

    procedure SMART_DrawDots(Dots: TPointArray);
    begin
      SMART_DrawDotsEx(True, Dots, clRed);
    end;


    {*******************************************************************************
    procedure SMART_DrawBoxEx(Clear: boolean; Box: TBox; Color: TColor);
    Contributors: Sir R. Magician, caused, mastaraymond
    Description: Draws a TBox onto the SMART Debug canvas
    *******************************************************************************}

    procedure SMART_DrawBoxEx(Clear: boolean; Box: TBox; Color: TColor);
    begin
    {$IFDEF SMART}
      with TBitmap.Create do
        try
          try
            Canvas.Handle := SmartGetDebugDC;
            Canvas.Pen.Color := Color;
           
            if (Clear) then
              ClearRSCanvas(Canvas);
             
            Canvas.MoveTo(Box.x1, Box.y1);
            Canvas.LineTo(Box.x2, Box.y1);
            Canvas.LineTo(Box.x2, Box.y2);
            Canvas.LineTo(Box.x1, Box.y2);
            Canvas.LineTo(Box.x1, Box.y1);
          except
            WriteLn(ExceptionToString(ExceptionType, ExceptionParam));
          end;
        finally
          Free;
        end;
    {$ENDIF}
    end;

    {*******************************************************************************
    procedure SMART_DrawBox(Box: TBox);
    Contributors: Sir R. Magician
    Description: Draws a TBox onto the SMART Debug canvas
    *******************************************************************************}

    procedure SMART_DrawBox(Box: TBox);
    begin
      SMART_DrawBoxEx(True, Box, clRed);
    end;

    {*******************************************************************************
    procedure SMART_DrawTextEx(Clear: Boolean; X, Y: Integer; Font, Text: string; Color: TColor);
    Contributors: Jukka, Shuttleu
    Description: Draws text onto the SMART Debug canvas at position x, y
    *******************************************************************************}

    procedure SMART_DrawTextEx(Clear: Boolean; X, Y: Integer; Font, Text: string; Color: TColor);
    var
      I, H, Height: integer;
      TPA: TPointArray;
    begin
      TPA := LoadTextTPA(Text, Font, Height);
      H := High(TPA);
      for I := 0 to H do
      begin
        IncEx(TPA[I].x, X);
        IncEx(TPA[I].y, Y);
      end;
      SMART_DrawDotsEx(Clear, TPA, Color);
    end;

    {*******************************************************************************
    procedure SMART_DrawText(X, Y: Integer; Font, Text: string; Color: TColor);
    Contributors: Shuttleu
    Description: Draws text onto the SMART Debug canvas at position x, y
    *******************************************************************************}

    procedure SMART_DrawText(X, Y: Integer; Font, Text: string; Color: TColor);
    begin
      SMART_DrawTextEx(False, X, Y, Font, Text, Color);
    end;

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

  6. #81
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Dgby, since you're freeing the bitmap at the end of the procedure, wouldn't that clear the canvas (i.e. nothing would be shown)? See this.

  7. #82
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Hey any of u know if its possible to free a dtm or bitmap ON TERMINATE? I dont mean having the script terminate itself but I mean when the user presses the stop button, it free's that stuff.. that way wouldnt it stop the memory leaks??

    And btw I believe drawing a blank bitmap on top of an existing one will pile the memory... U actually need to completely delete it from memory.. wipe it from existance as if it was never drawn before..
    Last edited by Brandon; 04-01-2011 at 04:09 PM.

  8. #83
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by ggzz View Post
    Hey any of u know if its possible to free a dtm or bitmap ON TERMINATE? I dont mean having the script terminate itself but I mean when the user presses the stop button, it free's that stuff.. that way wouldnt it stop the memory leaks??
    Simba frees unfreed bitmaps on terminate.

    Quote Originally Posted by ggzz View Post
    And btw I believe drawing a blank bitmap on top of an existing one will pile the memory... U actually need to completely delete it from memory.. wipe it from existance as if it was never drawn before..
    That's what I thought too, but Wizzup said that's not the case.

  9. #84
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    Quote Originally Posted by Coh3n View Post
    Dgby, since you're freeing the bitmap at the end of the procedure, wouldn't that clear the canvas (i.e. nothing would be shown)? See this.
    No, i need to make this longer than 3 characters....

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

  10. #85
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    "No."?

    Mind explaining why? Because when I freed the TBitmap at the end of the procedures in the current version, nothing was displayed, which makes sense in my mind. I can see that you wrote it a little differently, but to me it looks like it does the same thing, just in a different way.

  11. #86
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    Quote Originally Posted by Coh3n View Post
    "No."?

    Mind explaining why? Because when I freed the TBitmap at the end of the procedures in the current version, nothing was displayed, which makes sense in my mind. I can see that you wrote it a little differently, but to me it looks like it does the same thing, just in a different way.
    It does do the same thing, I don't know why, and yes I've tested it.
    It works.

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

  12. #87
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Lol well okay! Awesome then. I'll test when I get home to make sure there aren't any leaks. Thank.

Page 4 of 4 FirstFirst ... 234

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
  •