TsSkinProvider.PaintAll -> GDIError (EOutOfResources = out of memory)

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #71287
    SzakiLaci
    Participant

      I have a suspicion that this error has to do with Thread safety somehow.

      The “new” background thread I mentioned gives “out of memory” messages too, while the program’s mem-usage is under 150MB, and the OS has min. 1GB+ free RAM.
      (As You can see from attached bugreports. That thread is called: “HatterNTAK_szal”)

      I see that from my own LOGs:
      When a TUIBQuery component tries to load max 64 tiny rows from database. (Which is very small amount of data, max 1-2 Kbytes.) It can open that table, so the try..except writes: “out of memory” error to my LOG file.
      Maybe it has nothing to do with it, but that’s my only “similar error” starting point so far.

      Also checked the VGA-memory usage, no problems there either.

      Worth to mention that I’m using FastMM4 latest module, so that should be stable too.
      ( Of course with {$define AssumeMultiThreaded} enabled )

      • This reply was modified 2 years, 7 months ago by SzakiLaci.
      #71289
      SzakiLaci
      Participant

        Sorry, forgot to tell: I’m using 2019.05 version: v14.29

          object sSkinManager1: TsSkinManager
            SkinsFilter = [sfiInternal]
            Effects.AllowAnimation = False
            AnimEffects.DialogShow.Active = False
            AnimEffects.FormShow.Active = False
            AnimEffects.FormHide.Active = False
            AnimEffects.DialogHide.Active = False
            AnimEffects.Minimizing.Active = False
            AnimEffects.PageChange.Active = False
            AnimEffects.SkinChanging.Active = False
            AnimEffects.SkinChanging.Time = 0
            AnimEffects.SkinChanging.Mode = atDropDown
            ButtonsOptions.OldGlyphsMode = True
            ButtonsOptions.ModalButtonsColoring = []
            Active = False
            CommonSections.Strings = (
              '[PN_ATLATSZO]'
              'TRANSPARENCY=100'
              ''
        ...
            UseCache = False
            Bitmap = {}
        
        
          object sSkinProvider1: TsSkinProvider
            AllowAnimation = False
            AllowBlendOnMoving = False
            AllowSkin3rdParty = False
            ScreenSnap = True
            AllowExtBorders = False
            UseGlobalColor = False
            AddedTitle.Font.Charset = EASTEUROPE_CHARSET
            AddedTitle.Font.Color = clNone
            AddedTitle.Font.Height = -11
            AddedTitle.Font.Name = 'Arial'
            AddedTitle.Font.Style = []
            SkinData.SkinSection = 'FORM'
        ...
        

        I guess first thing You will recommend to upgrade it, but I’m afraid something similar may happen, as last time. (Worked several month long to correct all the anomalies.)

        #71292
        Lasse
        Participant

          I recommend asking ChatGPT e.g. “How to track GDIError (EOutOfResources = out of memory) errors in Delphi?”. It gives an excellent answer.

          I bet my money on creating GDI objects and not deleting them somewhere. I have seen that thousand times.

          #71293
          Lasse
          Participant

            That said… for example find “CreatePen” from AlphaSkins source and you will find a leak in sGraphUtils.pas:

            SelectObject(DC, CreatePen(PS_SOLID, 2, clWhite));

            That will create a pen and it is never deleted. The code should be like:

            var
              LPen: HPEN;
            begin
              LPen := CreatePen(...);
              try
                // Use the pen for drawing
              finally
                DeleteObject(LPen); // Release the GDI pen object
              end;
            end;
            • This reply was modified 2 years, 7 months ago by Lasse.
            #71297
            SzakiLaci
            Participant

              Thank you very much!
              I will change that.

              Can You please add a few more examples, what else to search for, not just “CreatePen” ?

              And yes, I’ve also noticed there are still some memory leaks in the code.
              But it seems it has improved a lot since the 2019 version.
              noticed Serge forgets to put:
              inherited Destroy;
              to the end of the Destroy procedures after all other “clearings”, instead of the beginning.

              2.
              Do you know if it’s enough to FreeAndNil(FTextTimer) a timer component, instead of first stopping it by :
              FTextTimer.Enabled := False;
              ?
              (like he does at: destructor TacCustomCombo.Destroy; )

              #71301
              Lasse
              Participant

                You can check what objects can be created for SelectObject.

                – Bitmap: CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap, CreateDIBitmap, CreateDIBSection
                – Brush: CreateBrushIndirect, CreateDIBPatternBrush, CreateDIBPatternBrushPt, CreateHatchBrush, CreatePatternBrush, CreateSolidBrush
                – Font: CreateFont, CreateFontIndirect
                – Pen: CreatePen, CreatePenIndirect
                – Region: CombineRgn, CreateEllipticRgn, CreateEllipticRgnIndirect, CreatePolygonRgn, CreateRectRgn, CreateRectRgnIndirect

                I have mostly seen CreatePen and CreateBrush leaks. But there are also many other kind of traps to fall into. The worst I know is SHGetFileInfo where you need to destroy the icon handle, if you are not using it. Usually you’re only interested in icon index.

                For example

                function GetIconIndex(const AFilename: string; const AFileAttributes: Cardinal; const AMoreFlags: Cardinal): Integer;
                var
                  LFileInfo: TSHFileInfo;
                begin
                  if SHGetFileInfo(PChar(AFilename), AFileAttributes, LFileInfo, SizeOf(TSHFileInfo), SHGFI_SYSICONINDEX or SHGFI_SMALLICON or
                    SHGFI_ICON or AMoreFlags) = 0 then
                    Result := -1
                  else
                  begin
                    Result := LFileInfo.iIcon;
                    { Important! Destroy the icon, we are only using the index. }
                    DestroyIcon(LFileInfo.hIcon);
                  end;
                end;
                #71302
                Lasse
                Participant

                  Yes, FreeAndNil(FTextTimer) is ok.

                  TTimer destroy will disable it.

                  destructor TTimer.Destroy;
                  begin
                    FEnabled := False;
                    ...
                  #71305
                  SzakiLaci
                  Participant

                    After I’ve upgraded to latest version=17.01
                    this error seems to disappeared. (But not tested enough yet… so it’s not final.)

                    But, other huge errors started to appear, like:
                    sendtoback-brings-the-form-to-foreground

                    #71307
                    chris2023
                    Participant

                      Solution

                      • This reply was modified 2 years, 7 months ago by chris2023.
                      #71310
                      SzakiLaci
                      Participant

                        Dear Chris2023,
                        Please delete your post.
                        This is not a solution.

                        #71316
                        SzakiLaci
                        Participant

                          After I’ve upgraded to latest version=17.01
                          this error seems to disappeared. (But not tested enough yet… so it’s not final.)

                          I take it back 🙁

                          It has turned out: the same error can still happen with the latest version too.
                          While it’s rare compared to the old one.

                          So I will put back the 2019 version, it was much much more stable and will enhance the AC code with the recommended try…finally and some try..except lines.

                        Viewing 11 posts - 1 through 11 (of 11 total)
                        • You must be logged in to reply to this topic.