Even "detached locals" can keep live reference to an object.
Very much true. But it is very rare that our programmers in normal course create a "detached local" pf the recordset.
As an example:
Code:
REDEFINE BUTTON...;
ACTION MYFUNC( oRs )
[/Code]
Please reconsider. This action clause creates a codeblock { || MYFUNC( oRs ) }.
The oRs is not detached. This codeblock always uses the current value of oRs in the calling program.
So there is no detached local in this case to retain a reference to the recordset.
A local (parameter) gets detached when the called program creates a codeblock using the parameter.
Example:
- Code: Select all Expand view
func callingfunction()
local oRs, b
// create oRs
b := CalledFunc( oRs )
Eval( b )
oRs:Close()
oRs := nil
Eval( b )
b := nil // now the detached local also is released. ActiveConnection also is closed
return nil
fun CalledFunc( oRs )
return { || MsgInfo( oRs:ActiveConnection:State }
Now the oRs get detached in the codeblock b. This detached local is live as long as the codeblock b is live. Even after the oRs in the called program is closed and set to nil, still Eval( b ) shows 1 ( meaining the activeconnection is still open). And when b is released by setting to nil or goes out of scope then the detached local ( referring to the recordset) also is released.
One can say XBrowse creates lots of codeblocks using the oRs.
Actually XBrowse does not create even a single codeblock using oRs received as parameter, but creates all codeblocks using ::oRs. Thereby there is not detached local referring to the recordset.
What I observed ( with xHarbour ) is this:
When oRs is assigned to the data of some Object, even after the Object goes out of scope, the reference to oRs in that Object's data is not released.
Example:
// oRs := Open Recset
o := TSomeClass()
o:oRs := oRs
...
...
later o := nil
still the reference of oRs in o:oRs is not released
This should have been explicitly released by some destructor method of the TSomeClass
Now thats what I have done.
TXBrowse's Destroy method sets ::oRs := nil
TDataRow class is not a control.
so I created DESTRUCTOR method and released oRs reference there.
Now I checked and the references to oRs are released cleanly