Memory leak !!

This forum is for posting of useful information
Post Reply
Message
Author
User avatar
jdsoft
Posts: 116
Joined: Thu Jan 28, 2010 1:13 pm
Location: Overberg
Contact:

Memory leak !!

#1 Post by jdsoft »

After days of debugging, and testing i found an issue that might be important to some of you.
xbpBrowse has an callback slot called xbpBrowse:StableBlock. (do not confuse this with xbpBrowse:ItemMarked)
The code block is called when the browse is stable. Even if the browse has no focus.
I use it for one to many browses, often in 2 or more levels.

If you assign the codeblock using the EVAL clause like:
DCBROWSE … EVAL {|o|o:StableBlock := bMyBlock} BE AWARE !!!
DO NOT REFERENCE OBJECTS FROM THE CURRENT GETLIST IN THIS CODEBLOCK. (ESPECIALY DCBROWSE) :naughty:
IOW: Only reference to objects that are already created (oXbp:Status = 1).
The folowing code snippes causes memory leaks after open and close the same window over and over again.
Notice DCBROWSE and DCREAD GUI

Code: Select all

LOCAL bRefreshRegels    := {|o|Asize(aDataRegels,0), oData := Dc_GetColArray(,o),;
                              Aeval(::aOrderRegels,{|o|iif(o:Orderid == oData:Orderid,Aadd(aDataRegels,o),nil)}),;
                              oBrowRegels:GoTop(),oBrowRegels:RefreshAll()}

@ nLine  , 2            DCBROWSE oBrowOrder DATA aDataOrder SIZE 100,nBrowHoogOrder FIT NOHSCROLL ;
                        CURSORMODE XBPBRW_CURSOR_ROW EVAL {|o|o:StableBlock := bRefreshRegels}

DCBROWSECOL OBJECTVAR "OrderId"                 HEADER TAAL_LBL_ORDER      PARENT oBrowOrder WIDTH 6
DCBROWSECOL OBJECTVAR "Typebon"                 HEADER TAAL_LBL_TYPE       PARENT oBrowOrder WIDTH 2
DCBROWSECOL OBJECTVAR "Datumgeleverd"           HEADER TAAL_LBL_LEVERDATUM PARENT oBrowOrder WIDTH 6
nLine += nBrowHoogOrder + 1
@ nLine  , 2            DCBROWSE oBrowRegels DATA aDataRegels SIZE 100,nBrowHoogRegels  FIT NOHSCROLL ;
                        CURSORMODE XBPBRW_CURSOR_ROW
DCBROWSECOL OBJECTVAR "RegelId"        HEADER "T"                    PARENT oBrowRegels WIDTH 3
DCBROWSECOL OBJECTVAR "ArtikelId"      HEADER TAAL_LBL_ARTIKEL       PARENT oBrowRegels WIDTH 4
DCBROWSECOL OBJECTVAR "Omschrijving"   HEADER TAAL_LBL_OMSCHRIJVING  PARENT oBrowRegels WIDTH 12
DCREAD GUI .....
This is the wrong way.
Doing so, will cause memory leaks. You can test this using MEMWATCH.
If you wish to use xbpBrowse:StableBlock feature to refresh other items in the window dependent of the active record in the browse, then you MUST assign the xbpBrowse:StableBlock in the EVAL clause of DCREAD GUI.

Code: Select all

LOCAL bRefreshRegels    := {|o|Asize(aDataRegels,0), oData := Dc_GetColArray(,o),;
                              Aeval(::aOrderRegels,{|o|iif(o:Orderid == oData:Orderid,Aadd(aDataRegels,o),nil)}),;
                              oBrowRegels:GoTop(),oBrowRegels:RefreshAll()}

@ nLine  , 2            DCBROWSE oBrowOrder DATA aDataOrder SIZE 100,nBrowHoogOrder FIT NOHSCROLL ;
                        CURSORMODE XBPBRW_CURSOR_ROW 

DCBROWSECOL OBJECTVAR "OrderId"                 HEADER TAAL_LBL_ORDER      PARENT oBrowOrder WIDTH 6
DCBROWSECOL OBJECTVAR "Typebon"                 HEADER TAAL_LBL_TYPE       PARENT oBrowOrder WIDTH 2
DCBROWSECOL OBJECTVAR "Datumgeleverd"           HEADER TAAL_LBL_LEVERDATUM PARENT oBrowOrder WIDTH 6
nLine += nBrowHoogOrder + 1
@ nLine  , 2            DCBROWSE oBrowRegels DATA aDataRegels SIZE 100,nBrowHoogRegels  FIT NOHSCROLL ;
                        CURSORMODE XBPBRW_CURSOR_ROW
DCBROWSECOL OBJECTVAR "RegelId"        HEADER "T"                    PARENT oBrowRegels WIDTH 3
DCBROWSECOL OBJECTVAR "ArtikelId"      HEADER TAAL_LBL_ARTIKEL       PARENT oBrowRegels WIDTH 4
DCBROWSECOL OBJECTVAR "Omschrijving"   HEADER TAAL_LBL_OMSCHRIJVING  PARENT oBrowRegels WIDTH 12
DCREAD GUI ..... EVAL {||oBrowOrder:StableBlock := bRefreshRegels}
I personaly use the xbpBrowse:StableBlock intensivly. I need to check all my code in different projects, and make corrections.
This issue was the cause for dramatic slowdown of my app after using it for several hours.

Regards,
Jack Duijf
Regards,
Jack Duijf

Post Reply