Web Connection
Dispose
Gravatar is a globally recognized avatar based on your email address. Dispose
  Luca
  All
  Feb 10, 2021 @ 09:57pm

Dear Rick,
I developed 6 applications with WC file-mode for a customer and casually some of them wait for no reason and without generating an error on server.
On this screenshot from server, there are 9 instances waiting "no reply".

Sometime I get this error even if I click on Exit button, as if it were a release memory problem, so I wonder if I use che right Dispose().
In every page I put a Dispose() function like the following, where I release every object/property of the webpage:

****************
FUNCTION Dispose()
****************
IF USED("qAnagrafica")
	USE IN qAnagrafica
ENDIF 
DODEFAULT()
WITH this
	.oBusiness=null
	.cTitolo=null
	.cLingua=null
	.cIdOperator=null
	.nE0=null
	.CTL0002 = null
	.Header = null
	.CTL0004 = null
	.CTL0005 = null
	.CTL0006 = null
	.WwWebLiteral1 = null
	.CTL0008 = null
	.CTL0009 = null
	.CTL0010 = null
	.form1 = null
	.CTL0012 = null
	.Nuovo = null
	.CTL0014 = null
	.txtIdFunzionario = null
	.CTL0016 = null
	.ErrorDisplay = null
	.CTL0018 = null
	.Grid1 = null
	.Column1 = null
	.Column2 = null
	.Column3 = null
	.Column4 = null
	.Column5 = null
	.CTL0025 = null
	.CTL0026 = null
	.CTL0027 = null
ENDWITH
ENDFUNC

Is correct this way to use Dipose()?
Is it a better way to release resources?
How to understand if resources are released rightly?
Thank you very much for support

Gravatar is a globally recognized avatar based on your email address. re: Dispose
  Luca
  Luca
  Feb 16, 2021 @ 09:45pm

Hi Rick,
why some post gets reply and some not?

Gravatar is a globally recognized avatar based on your email address. re: Dispose
  Rick Strahl
  Luca
  Feb 17, 2021 @ 01:13pm

I have no idea based on your limited description.

You show several different applications running, some files in Task manager and you say "it doesn't work".

Not helpful...

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Dispose
  Luca
  Rick Strahl
  Feb 17, 2021 @ 09:31pm

All the applications showed are developed with Web Connection and they work very well.
I do not understand why sometimes they do not release when I click the Exit button.

I suspect there is a problem with memory release.
Please is correct the showed use of Dispose?
I release every object/property on every webpage.
Thank you very much for support

Gravatar is a globally recognized avatar based on your email address. re: Dispose
  Marcel DESMET
  Luca
  Feb 17, 2021 @ 11:48pm

Hello Luca

This.oBusiness=null release only a object reference, the business object is released only if there is only one reference to this object ( this.oBusiness ).

Pendind object with multiple references is a common problem in foxpro which requires a good structure of the code

Gravatar is a globally recognized avatar based on your email address. re: Dispose
  Luca
  Marcel DESMET
  Feb 17, 2021 @ 11:58pm

Hi Marcel,
excuse me but I do not understand how I should release rightly every page reference.
Can you show an example?
Thank you very much

Gravatar is a globally recognized avatar based on your email address. re: Dispose
  FoxInCloud Support - Thierry N.
  Luca
  Feb 18, 2021 @ 02:41am

Ciao Luca,

The so-called 'VFP garbage collector' automatically releases objects when their reference count (either properties or variables referencing the object) is = 0.

The only case where YOU HAVE to release objects explicitly is mutual reference; eg.

local o1, o2
o1 = createObject('Empty') && object 1
o2 = createObject('Empty') && object 2
addProperty(m.o1, 'o2', m.o2)
addProperty(m.o1.o2, 'o1', m.o1)
release o1, o2
&& When releasing variable `o1`, VFP can't release object 1 because it has a reference remaining in `o2.o1`;
&& same when releasing variable 'o2'.
&& In the end, both objects 1 & 2 remain hanged in memory.

.destroy() fires only when object is released (not only the variable holding the reference), so hook methods such as .dispose() don't even fire in a similar case.

You can avoid mutual references by replacing

addproperty(this, 'someProp', createObject('someClass'))

by

this.addObject('name', 'someClass')

In this case the parent object can address any PEM of the child using this.name.*, and the child can address any PEM of the parent using this.Parent.*

VFP takes care internally of this mutual reference.

The only drawback is the limitation in the classes that can be parent and/or child. The only non-visual class that work for both is Custom. Unfortunately Session can't execute .addObject().

Gravatar is a globally recognized avatar based on your email address. re: Dispose
  Luca
  FoxInCloud Support - Thierry N.
  Feb 18, 2021 @ 05:00am

Dear Thierry,
I understand the releasing difficulty, as showed from you and Tore.
In Dispose I scan every prg, beyond the line

*# --- BEGIN GENERATED CODE BOUNDARY --- #*

then extract every objects/properties on the page and put them "=null" as showed above.
Do you think this is a good way to limit memory consumption, or is there a better way to close pages and clean memory?
Many thanks for support

Gravatar is a globally recognized avatar based on your email address. re: Dispose
  Rick Strahl
  Luca
  Feb 19, 2021 @ 12:41pm

You need to understand that undisposed objects is only one thing that can cause hung instances. Other things are open dialogs (ie. a file open dialog or access warning), as well as incorrect server shutdowns.

If you're running in File Mode objects won't clean up when crashed or hung. COM Mode can try to clean up when servers fail or time out.

You can also try to unload from the module admin page. If you switch to file mode (if running in COM) and you do Unload Servers it will try to kill all the EXEs that are running (based on the ExeFile configuration key).

But again - you throw this out here without any information on what you're actually doing and expect us to figure out what's wrong...

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Dispose
  Luca
  Rick Strahl
  Feb 19, 2021 @ 11:20pm

Many thanks to all for support.

Gravatar is a globally recognized avatar based on your email address. re: Dispose
  FoxInCloud Support - Thierry N.
  Luca
  Feb 20, 2021 @ 03:45am

As I wrote earlier, regarding hanged objects and memory leaks, the ONLY useful instruction is breaking the mutual reference(s). VFP garbage collector does ALL the rest automatically.

local o1, o2
o1 = createObject('Empty') && object 1
o2 = createObject('Empty') && object 2
addProperty(m.o1, 'o2', m.o2)
addProperty(m.o1.o2, 'o1', m.o1)
…
o1.o2.o1 = null && << only this is useful
release o1, o2 && useless, VFP takes care of that.

Beyond hanged objects, make sure to use 'unattended server mode' and COM mode in production.

© 1996-2021