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
Hi Rick,
why some post gets reply and some not?
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 ---
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
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
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
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()
.
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
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 ---
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.