HMG4 release method

Moderator: Rathinagiri

User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

HMG4 release method

Post 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.
Luigi from Italy
www.L3W.it
User avatar
concentra
Posts: 256
Joined: Fri Nov 26, 2010 11:31 am
Location: Piracicaba - Brasil

Re: HMG4 release method

Post 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 ?
[[]] Mauricio Ventura Faria
mrduck
Posts: 497
Joined: Fri Sep 10, 2010 5:22 pm

Re: HMG4 release method

Post 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.
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Re: HMG4 release method

Post 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
Luigi from Italy
www.L3W.it
User avatar
concentra
Posts: 256
Joined: Fri Nov 26, 2010 11:31 am
Location: Piracicaba - Brasil

Re: HMG4 release method

Post 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.
[[]] Mauricio Ventura Faria
User avatar
concentra
Posts: 256
Joined: Fri Nov 26, 2010 11:31 am
Location: Piracicaba - Brasil

Re: HMG4 release method

Post 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 ?
[[]] Mauricio Ventura Faria
mrduck
Posts: 497
Joined: Fri Sep 10, 2010 5:22 pm

Re: HMG4 release method

Post 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...
User avatar
apais
Posts: 440
Joined: Fri Aug 01, 2008 6:03 pm
DBs Used: DBF
Location: uruguay
Contact:

Re: HMG4 release method

Post 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
Angel Pais
Web Apps consultant/architect/developer.
HW_apache (webserver modules) co-developer.
HbTron (Html GUI for harbour desktop hybrid apps) co-developer.
https://www.hbtron.com
User avatar
concentra
Posts: 256
Joined: Fri Nov 26, 2010 11:31 am
Location: Piracicaba - Brasil

Re: HMG4 release method

Post 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.
[[]] Mauricio Ventura Faria
Carlos Britos
Posts: 245
Joined: Sat Aug 02, 2008 5:03 pm

Re: HMG4 release method

Post 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
Regards/Saludos, Carlos (bcd12a)
Post Reply