Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Possible WISH LIST item?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00149579
Message ID:
00150120
Vues:
27
Hi Rick,

>Didn't know that... Are you sure? Reason I ask I've had major problems
>with hanging references in the past and nothing I tried at the time would
>release the object short of explicitly going through all the child
>references.

OK, here's a sample to clarify what I mean. The following code is what many developers usually write:
Public ox, oy, oz
ox = Create("Form")
oz = ox
ox.AddObject("Text1","Textbox")
ox.Show
oy = ox.Text1
If you try to release the form, it stays on the screen. OX is already .NULL., the same is valid for oz, because the Release() method can by default nullify all references to the object itself. This won't work, of course, for object that don't have a Release method, nor does the same reliable happen if you release an object by letting it go out of scope. But because of the reference oy to one of it's members, the form is still there, that's what we call a dangling reference.

But if you run the following code instead:
Public ox, oy, oz
ox = Create("myForm")
oz = ox
ox.AddObject("Text1","Textbox")
ox.Show
oy = ox.Text1

Define Class myForm as Form
   Procedure Release
      Release This
   EndProc
   Procedure Destroy
      This.RemoveObject("Text1")
   Endproc
Enddefine
The form closes without any problems. RELEASE THIS is here not necessary, but it's for example in a label class. The point here is RemoveObject() which removes the textbox even when there's a reference pointing to it. oy is .NULL. after the RemoveObject() line has been executed. The default behavior of Destroy() is to finally release the object, and when VFP tries to do this, there's no object on the form anymore. Thus, it can't find any dangling references and releases the form just fine.

All of our baseclasses have this code in it (generic code, we just loop through the controls collection) and I really can't remember the last time when I had a problem because of a dangling reference. This technique is called cascading destroy, and the difference to usual release strategies is that it releases an object from the innermost to the outermost control. The first object here that is released is the textbox, not the form. If there would be a pageframe on the form, first all objects on the pages, then the pages, then the pageframe and finally the form would be released. Therefore no control on a form can prevent the form from being released, and that's what dangling references are mainly about.

Christof
--
Christof
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform