Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Collection with multiple refs to the same object - Bug
Message
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00843625
Message ID:
00843888
Views:
24
Larry,

see the update at the bottom...

>Calling the Release method of the form class actually removes it from the collection. The only reference to the form class I found after releasing both the form variable and the colection object itself, was in the Forms collection of both _VFP and _Screen.
>
>Issuing a Clear All was the only thing I found to actually release the held object reference.

This is not my experience. Why should releasing the form cause the collection to lose its object reference? There is no link from the form or its memvar to the collection. The link is the other way round, from the collection to the form.

This code sample works exactly as I mentioned in the first post:
public oColl && not needed if running line by line in the command window

oColl = createobject( "collection" ) && creates the collection

o2 = createobject( "form" ) && creates a form
o2.Visible = .t. && it's visibility is a "easier" way to see if it's alive and kicking

oColl.Add( o2, "test" ) && add a reference to the form to the collection, the form object reference increments to 2

release o2 && or o2 = .null. && form reference count decrements to 1, form still visible

oColl.Remove( "test" ) && clear the reference the collection is holding, form destructs.
Update to the original reply. I wasn't quite testing the same thing. I didn't explicitly call the form.Release() method. I'm honestly suprised that it can clear any and all outstanding object references to the form. But it does and this behavior goes back to VFP6. It may do this in order to clear the _screen.Forms[] collection. This is amazingly pervasive, I tried creating a oRef property on the form and setting it to this, creating a public memvar with a reference and a property of a contained object to the form and just calling thisform.Release() from another button, and VFP goes through and nukes all of the object references to the form. I learned something new tonight.
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Reply
Map
View

Click here to load this message in the networking platform