GDIPlus functions cause a memory leak.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #37921
    HeDiBo
    Participant

    In the acgpUtils.pas there is this piece of code in the procedure acgpBlur:

    Code:
    acGdipBitmapCreateApplyEffect(@NativeInputs[0], 1, NativeHandle, @R, @R, OutBitmap, False, OutAux, OutAuxSize);
    acGdipCreateHBITMAPFromBitmap(OutBitmap, OutBmp, 0); // <<< This causes a memory leak.
    Bmp.Handle := OutBmp;
    end;
    finally
    acGDIEnd(IsLibrary);
    end;

    Just calling GdiplusShutdown (acGDIEnd) is not enough to free resources. This is from the Microsoft docs on GDI+:

    “You must call GdiplusStartup before you create any GDI+ objects, and you must delete all of your GDI+ objects (or have them go out of scope) before you call GdiplusShutdown.”

    So, this creates a memory leak.

    Another memory leak occurs because of this piece of code in TsSplitView.UpdateBGBmp:

    Code:
    if BGBmp = nil then
    BGBmp := CreateBmp32(Size)
    else begin
    BGBmp.Width := Size.cx;
    BGBmp.Height := Size.cy;
    end;

    Apparently BGBmp is not freed in my project. I think this should probably be done with a global list of BGBmp's that is freed in the Finalization section.

    This memory leak occurs in a number of places.

    Here is the memory leak log:

    [attachment=8870:WIP4_MemoryManager_EventLog.txt]

    #58311
    Support
    Keymaster

    Hello and thank you for researching.

    I will check and fix it.

    #58313
    HeDiBo
    Participant
    'Support' wrote:

    Hello and thank you for researching.

    I will check and fix it.

    I found that removing the memory leak from TsSplitView, removes the other ones too.

    This change did it:

    Code:
    destructor TsSplitView.Destroy;
    begin
    FBlurData.Free;
    FreeAndNil(BGBmp); (*** DB ***)
    FreeAndNil(BluredBmp); (*** DB ***)
    inherited;
    end;

    #58323
    Support
    Keymaster

    Hello and thank you for the information.

    I have checked GDI Plus functions, GdiplusStartup is called there in the acGDIBegin procedure.

    Memory leak will be removed very soon I think, some problems with reproduction of the problem exists.

    #58315
    HeDiBo
    Participant
    'Support' wrote:

    Hello and thank you for the information.

    I have checked GDI Plus functions, GdiplusStartup is called there in the acGDIBegin procedure.

    Memory leak will be removed very soon I think, some problems with reproduction of the problem exists.

    The problem is only in TsSplitView, as mentioned above. Freeing the bitmaps mentioned will solve the memory leak.

    #58316
    Support
    Keymaster

    Yes, this code should work, but it will be great if I can find a reason of this leak.

    #58317
    HeDiBo
    Participant
    'Support' wrote:

    Yes, this code should work, but it will be great if I can find a reason of this leak.

    In sPanel the allocation of BGBmp especially is a bit fishy. It is very hard to find why it is freed if the application is stopped when the bitmap is allocated.

    #58390
    HeDiBo
    Participant

    Solved. a3.gif

    (You didn't need to keep my initials in the bug fix, but I appreciate it.) rolleyes.gif

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