Page 1 of 5

HMG4 release method

Posted: Tue Jul 19, 2011 5:08 pm
by l3whmg
Hi to everyone.
Please, is there someone that tell me why it was introduced this code:

Code: Select all

METHOD Release() CLASS BASIC

   // Some QT classes do not have close()
   IF !( ::cClass = "MENUITEM"  .OR.;
         ::cClass = "SOUND"     .OR.;
         ::cClass = "TIMER"     .OR.;
         ::cClass = "LAYOUTBOX" .OR.;
         ::cClass = "LAYOUTFORM".OR.;
         ::cClass = "LAYOUTGRID"      )

      ::oQTObject:close()

   ENDIF

   RETURN Self
and I find (ie within samples\mainmenu\demo_1.prg) this:

Code: Select all

   oPopupFile:Release()
   oPopupHelp:Release()
   oPopupMore:Release()
   oPopupEdit:Release()
   oItemOpen:Release()
   oItemClose:Release()
   oItemMore1:Release()
   oItemMore2:Release()
   oItemMore3:Release()
   oItemCut:Release()
   oItemCopy:Release()
   oItemPaste:Release()
   oItemAbout:Release()
   oItemSave:Release()
   oButton1:Release()
   oButton2:Release()
   oButton3:Release()
   oButton4:Release()
   oButton5:Release()
   oButton6:Release()
   oButton7:Release()
   oButton8:Release()
   oButton9:Release()
   oButton10:Release()
The Release method was used (HMG3) with window "object"!
There are other problems that I do not know which require the use? We must use Release for any control?

Many thanks in advance.

Re: HMG4 release method

Posted: Wed Jul 20, 2011 1:11 pm
by concentra
l3whmg wrote:Hi to everyone.
Please, is there someone that tell me why it was introduced this code:

Code: Select all

METHOD Release() CLASS BASIC

   // Some QT classes do not have close()
   IF !( ::cClass = "MENUITEM"  .OR.;
         ::cClass = "SOUND"     .OR.;
         ::cClass = "TIMER"     .OR.;
         ::cClass = "LAYOUTBOX" .OR.;
         ::cClass = "LAYOUTFORM".OR.;
         ::cClass = "LAYOUTGRID"      )

      ::oQTObject:close()

   ENDIF

   RETURN Self
Hi Luigi, that was me.
This is because the QT related objects don't have the Close() method.
and I find (ie within samples\mainmenu\demo_1.prg) this:

Code: Select all

   oPopupFile:Release()
   oPopupHelp:Release()
   oPopupMore:Release()
   oPopupEdit:Release()
   oItemOpen:Release()
   oItemClose:Release()
   oItemMore1:Release()
   oItemMore2:Release()
   oItemMore3:Release()
   oItemCut:Release()
   oItemCopy:Release()
   oItemPaste:Release()
   oItemAbout:Release()
   oItemSave:Release()
   oButton1:Release()
   oButton2:Release()
   oButton3:Release()
   oButton4:Release()
   oButton5:Release()
   oButton6:Release()
   oButton7:Release()
   oButton8:Release()
   oButton9:Release()
   oButton10:Release()
The Release method was used (HMG3) with window "object"!
There are other problems that I do not know which require the use? We must use Release for any control?
Many thanks in advance.
Me too.
Not really sure, but if an object isn't "released" doesn't it retains some memory ?

Re: HMG4 release method

Posted: Wed Jul 20, 2011 1:34 pm
by mrduck
concentra wrote:
l3whmg wrote:Hi to everyone.
Please, is there someone that tell me why it was introduced this code:

Code: Select all

METHOD Release() CLASS BASIC

   // Some QT classes do not have close()
   IF !( ::cClass = "MENUITEM"  .OR.;
         ::cClass = "SOUND"     .OR.;
         ::cClass = "TIMER"     .OR.;
         ::cClass = "LAYOUTBOX" .OR.;
         ::cClass = "LAYOUTFORM".OR.;
         ::cClass = "LAYOUTGRID"      )

      ::oQTObject:close()

   ENDIF

   RETURN Self
Hi Luigi, that was me.
This is because the QT related objects don't have the Close() method.


Ok, so the best to do in a OOP world is to override METHOD Release in MENUITEM SOUND LAYOUTBOX etc to do the close() and keep an "empty" METHOD Release in basic.prg

what do you think ?

and I find (ie within samples\mainmenu\demo_1.prg) this:

Code: Select all

   oPopupFile:Release()
   oPopupHelp:Release()
   oPopupMore:Release()
   oPopupEdit:Release()
   oItemOpen:Release()
   oItemClose:Release()
   oItemMore1:Release()
   oItemMore2:Release()
   oItemMore3:Release()
   oItemCut:Release()
   oItemCopy:Release()
   oItemPaste:Release()
   oItemAbout:Release()
   oItemSave:Release()
   oButton1:Release()
   oButton2:Release()
   oButton3:Release()
   oButton4:Release()
   oButton5:Release()
   oButton6:Release()
   oButton7:Release()
   oButton8:Release()
   oButton9:Release()
   oButton10:Release()
The Release method was used (HMG3) with window "object"!
There are other problems that I do not know which require the use? We must use Release for any control?
Many thanks in advance.
Me too.
Not really sure, but if an object isn't "released" doesn't it retains some memory ?

Objects are "fully released" when the harbour object is released. It is not necessary to do the :release() stuff just to free memory. If it is necessary aka an error happens if you don't release() there is an error somewhere so please report.

Re: HMG4 release method

Posted: Wed Jul 20, 2011 1:49 pm
by l3whmg
Ok, so as MrDuck write
mrduck wrote:Objects are "fully released" when the harbour object is released
it's better to remove the code within examples else like me other can take a bad idea.
On the other hand, If we want close an object (this it's not HMG3 compliant, but...) we can preserve the idea, but with
mrduck wrote:Ok, so the best to do in a OOP world is to override METHOD Release in MENUITEM SOUND LAYOUTBOX etc to do the close() and keep an "empty" METHOD Release in basic.prg
.

Please can someone help with this viewtopic.php?f=32&t=2028

Cheers

Re: HMG4 release method

Posted: Wed Jul 20, 2011 1:57 pm
by concentra
Ok, so the best to do in a OOP world is to override METHOD Release in MENUITEM SOUND LAYOUTBOX etc to do the close() and keep an "empty" METHOD Release in basic.prg
You are right. I will revise this.

Re: HMG4 release method

Posted: Wed Jul 20, 2011 2:00 pm
by concentra
mrduck wrote:Objects are "fully released" when the harbour object is released.
This is a little bit gray to me... I do not really know this in deep.
Could you please explain when a harbour object is released ? Or point where can I find this info ?

Re: HMG4 release method

Posted: Wed Jul 20, 2011 2:29 pm
by mrduck
concentra wrote:
mrduck wrote:Objects are "fully released" when the harbour object is released.
This is a little bit gray to me... I do not really know this in deep.
Could you please explain when a harbour object is released ? Or point where can I find this info ?
How many hours do you have available ? :-)

Standard harbour objects are released when:
- they go out of scope
- they are set := NIL
You can check this by adding a destructor to the class
Out of scope means that the variable is no longer visible. PUBLICs are never released.

Harbour objects that are linked to low-level external structures handled by different libraries like in hbQt case and a couple of others cases are instead freed in a very different way: harbour object is no more usable from a prg level program but the variable is put on a special list and from time to time the garbage collector call a routine specified durint object creation and this routine reports if the object can be finally destroyed or not. Sorry, it's a very basic explanation, if you want I can send you a couple of messages from Przemek...

Re: HMG4 release method

Posted: Wed Jul 20, 2011 3:49 pm
by apais
Concentra:

In big terms ( experienced programmers don't kill me for this asseveration ), object containers are the same as array containers in behaviour.

When an object is released ?, same rules than an array variable applies.

aVar := {} // creation
aVar := nil // release

oVar := xClass:new() // creation
oVar := nil // release

Is it clearer now ??

HTH
Angel

Re: HMG4 release method

Posted: Wed Jul 20, 2011 4:30 pm
by concentra
mrduck wrote:if you want I can send you a couple of messages from Przemek...
Please !
Is this big ? If not, post here since other people may be interested too.

Re: HMG4 release method

Posted: Wed Jul 20, 2011 11:12 pm
by Carlos Britos
Hi
I've made this change to this code some time ago, if someone want to test it, replace in basic.prg and remove release method in control.prg
Is recursive and clean the array ::aControls. No need to release each control in code.

Code: Select all

/*----------------------------------------------------------------------*/

METHOD Release() CLASS BASIC

   LOCAL i

   // Some QT classes do not have close()
   IF ! ( ::cClass == "MENUITEM"   .OR. ;
          ::cClass == "SOUND"      .OR. ;
          ::cClass == "TIMER"      .OR. ;
          ::cClass == "LAYOUTBOX"  .OR. ;
          ::cClass == "LAYOUTFORM" .OR. ;
          ::cClass == "LAYOUTGRID" )

      // release QT object
      ::oQTObject:close()

   ENDIF

   // Release all child objects in it.
   // Recursive !
   FOR i := 1 TO Len( ::aControls )
      IF hb_IsObject( ::aControls[ i ] )
         ::aControls[ i ]:Release()
      ENDIF
   NEXT

   // Remove from the parent pool control
   FOR i := 1 TO Len( ::oParent:aControls )
      IF hb_IsObject( ::oParent:aControls[ i ] )
         IF ::oParent:aControls[ i ]:Name == ::Name
            ::oParent:aControls[ i ] := Nil
         ENDIF
      ENDIF
   NEXT

   RETURN Self