Page 1 of 1

Font release

PostPosted: Sat Sep 11, 2010 6:36 am
by Richard Chidiak
Antonio

We still have unrelased fonts when we use bgotfocus with xbrowse for instance, and i guess this happens with other controls also with gotfocus

This is a snapshot of my checkres.txt

My xbrowse in this particular program is using bgotfocus ..... , if i comment the line the fonts get released

Thanks for your help,

Richard

FONT,235542300,INITPLAN(457)->(b)PLANCHA00(407)->TCONTROL:GOTFOCUS(998)->(b)TXBROWSE:TXBROWSE(437)->TXBROWSE:GOTFOCUS(0)->TWINDOW:HANDLEEVENT(0)->TCONTROL:HANDLEEVENT(1499)->TXBROWSE:HANDLEEVENT(11063)->_FWH(3393)->SETFOCUS(0)->TWINDOW:GOTFOCUS(2596)->TWINDOW:HANDLEEVENT(0)->_FWH(3393)->SETFOCUS(0)->TWINDOW:SETFOCUS(2790)->FINPLANCH(354)->(b)PLANCHANT(253)->TBTNBMP:CLICK(463)->TBTNBMP:LBUTTONUP(658)->TBTNBMP:LBUTTONDOWN(598)->TCONTROL:HANDLEEVENT(1483)->TBTNBMP:HANDLEEVENT(1437)->_FWH(3393)->SYSREFRESH(0)->STOPUNTIL(60)->DFSAP(9538)->DEVPREP(6072)->MAJDET(1118)->DEVISCOR(61)->DEVFACMAJ(1373)->(b)DEVLIST(817)->TWINDOW:LDBLCLICK(1872)->TCONTROL:LDBLCLICK(1514)->TXBROWSE:LDBLCLICK(3470)->TWINDOW:HANDLEEVENT(0)->TCONTROL:HANDLEEVENT(1499)->TXBROWSE:HANDLEEVENT(11063)->_FWH(3393)->DIALOGBOX(0)->TDIALOG:ACTIVATE(279)->DEVLIST(922)->(b)MENUDEV(1196)->TMENU:COMMAND(437)->TWINDOW:COMMAND(1029)->TWINDOW:HANDLEEVENT(0)->_FWH(3393)->WINRUN(0)->TWINDOW:ACTIVATE(978)->MAIN(258)

Re: Font release

PostPosted: Sat Sep 11, 2010 6:53 am
by nageswaragunupudi
It is possible that a new font is created in the application program INITPLAN. If so the responsibility of finally releasing the font is that of the application program.

Re: Font release

PostPosted: Sat Sep 11, 2010 7:06 am
by Richard Chidiak
Mr Rao

The font is released at the end of the program

If i remove the obrw:bgotfocus line, the checkres.txt does not show the font which means that the gotfocus is keeping the font

Hth

Richard

Re: Font release

PostPosted: Sat Sep 11, 2010 7:23 am
by Antonio Linares
Richard,

What actions does your app from such bGotFocus ?

Re: Font release

PostPosted: Sat Sep 11, 2010 7:36 am
by Richard Chidiak
Antonio

This is the line

oBrWPLC:bGotFocus := {|| (IF( FILE(TRANS[04] + ".DBF"),dbSelectArea(TRANS[04]), ) , IF(SELECT(TRANS[04]) = 0, INITPLAN(TRANS) , ) ) }

STATIC FUNCTION INITPLAN(TRANS)
FOR I = 1 TO LEN(TRANS[09]) // FONT
IF TRANS[09][I] # NIL
TRANS[09][I]:END() // FONT
ENDIF
NEXT

DEFINE FONT TRANS[09][1] NAME "ARIAL" SIZE 0,-16 BOLD
DEFINE FONT TRANS[09][2] NAME "ARIAL BLACK" SIZE 0,-14 UNDERLINE
DEFINE FONT TRANS[09][3] NAME "ARIAL BLACK" SIZE 0,-12
DEFINE FONT TRANS[09][4] NAME "ARIAL BLACK" SIZE 0,-10

...

Re: Font release

PostPosted: Sat Sep 11, 2010 7:40 am
by Antonio Linares
Richard,

Do you End() the fonts in TRANS[09][I] at the end of your app ?

Re: Font release

PostPosted: Sat Sep 11, 2010 7:41 am
by Richard Chidiak
Antonio

yes

this is the end routine

Code: Select all  Expand view


STATIC FUNCTION FINPLANCH(obrwplc,TRANS,TPAR)
IF TRANS[24] # NIL   // BRUSH
   TRANS[24]:END()
ENDIF

IF TRANS[15] # NIL   // BAR
   TRANS[15]:END()
ENDIF

IF obrwplc # NIL
   obrwplc:END()
   obrwplc := NIL
ENDIF

FOR I = 1 TO LEN(TRANS[09])  // FONT
   IF TRANS[09][I] # NIL
      TRANS[09][I]:END() // FONT
   ENDIF
NEXT

IF TRANS[04] # NIL   // FUSER
   IF FILE(TRANS[04] + ".DBF")
      CLOSEFIC(TRANS[04])
      ERASE (TRANS[04]) + ".DBF"
   ENDIF
ENDIF

IF wndpcmain # NIL
   wndpcmain:SetFocus()
   wndpcmain:PostMsg(WM_CLOSE)
   wndpcmain := NIL
ENDIF
RETURN .T.
 

Re: Font release

PostPosted: Sat Sep 11, 2010 7:51 am
by Antonio Linares
Richard,

Both the fonts and the brushes use a users counter to control shared owners. Please add this code:
Code: Select all  Expand view

      TRANS[09][I]:END() // FONT
      MsgInfo( TRANS[09][I]:nCount )
 

If there are no more (GDI object) users then nCount should be zero. This may help to locate where the font counter is not decreased or extra increased. Thanks! :-)

Re: Font release

PostPosted: Sat Sep 11, 2010 7:58 am
by Richard Chidiak
Antonio

font1 = 4
font2 and 3 and 4 are 0

Richard

Re: Font release

PostPosted: Sat Sep 11, 2010 8:04 am
by Richard Chidiak
Antonio

This may help

the font is basically used this way

@ 15,70 SAY TRANS[28][1] PROMPT TRANS[26] OF TRANS[15] PIXEL SIZE 150,40 FONT TRANS[09][1] COLOR CLR_HBLUE CENTERED
@ 15,800 SAY TRANS[28][11] PROMPT TRANS[17] OF TRANS[15] PIXEL SIZE 150,40 FONT TRANS[09][1] COLOR CLR_HBLUE CENTERED UPDATE
obrwplc:aCols[X]:oheaderFont := TRANS[09][1]

Richard

Re: Font release

PostPosted: Sat Sep 11, 2010 8:39 am
by nageswaragunupudi
This posting of mine does not directly deal with the above problem, but .

It is always a safe practice to create fonts at the entry point and release them at the exit point and to avoid creation in a routine that is conditionally executed.

This practice greatly reduces the chance of obscure possibility of non-release of resources, which can be too difficult to debug.

Also assignment of fonts to a control/window should be by Obj:SetFont( oFont ) and not as obj:oFont := oFont.