amiga-mui / muidev

:mage_man: Magic User Interface (MUI) – Documentation+Releases
http://muidev.de
55 stars 0 forks source link

Memory leak in bitmap object handling #363

Open dmcoles opened 1 year ago

dmcoles commented 1 year ago

while developing a tool using MUI 5 I believe I have discovered a memory leak when handling BitmapObject with MUIA_Bitmap_Transparent set to 0.

The following AmigaE code replicates the issue


OPT STACK=35000

  MODULE 'muimaster' , 'libraries/mui'
  MODULE 'tools/boopsi'
  MODULE 'intuition/classusr','exec/memory','graphics/gfx'
  MODULE 'dos/dos'

PROC main()
  DEF bitmapItem
  DEF bitmap:PTR TO bitmap
  DEF planes
  DEF windowGroupRoot
  DEF winMain
  DEF i
  DEF app

  IF ( muimasterbase := OpenLibrary( 'muimaster.library' , MUIMASTER_VMIN ) )
    NEW bitmap
    InitBitMap(bitmap,1,128,30)
    planes:=NewM(16*30,MEMF_CHIP OR MEMF_CLEAR)
    bitmap.planes[0]:=planes

    app := Mui_NewObjectA('Application.mui',[
      MUIA_Application_Window , winMain := Mui_NewObjectA('Window.mui',[
        MUIA_Window_RootObject ,  windowGroupRoot := Mui_NewObjectA('Group.mui',[
          MUIA_Group_Child, bitmapItem:=Mui_NewObjectA('Bitmap.mui',[
            MUIA_Bitmap_Height,30,
            MUIA_Bitmap_Width,128,
            MUIA_Bitmap_Transparent,0,
            MUIA_Bitmap_Bitmap,bitmap,
          0]),
        0]),
      0]),
    0])

    set( winMain ,MUIA_Window_Open , MUI_TRUE )

    FOR i:=0 TO 100
      EXIT CtrlC()
      Delay(50)
      domethod(windowGroupRoot,[MUIM_Group_InitChange])
      domethod(windowGroupRoot,[OM_REMMEMBER,bitmapItem])
      domethod(windowGroupRoot,[OM_ADDMEMBER,bitmapItem])
      domethod(windowGroupRoot,[MUIM_Group_ExitChange])
      Execute('avail flush',0,0)
    ENDFOR

    Mui_DisposeObject(app)
    IF bitmap THEN END bitmap
    IF planes THEN Dispose(planes)

  ENDIF
  IF muimasterbase  THEN CloseLibrary( muimasterbase )
ENDPROC

Simply removing and re-adding the bitmap object from the parent group in a loop causes the memory usage to increase each time around the loop.

dmcoles commented 1 year ago

leak

tboeckel commented 1 year ago

Does this happen without MUIA_Bitmap_Transparent=0 as well?

dmcoles commented 1 year ago

No it doesn't happen without that.