Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to release and assign an object
Message
De
14/09/2006 09:07:01
 
 
À
13/09/2006 17:34:01
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Versions des environnements
Visual FoxPro:
VFP 9
Divers
Thread ID:
01153528
Message ID:
01153641
Vues:
16
>>I wonder whether I could get some feedback on the following problems.
>>
>>I have a few lines of codes to create an object, use it, and release it later.
>>
>>o1 = createobject("my_object")
>>......
>>
>>oCurrent = o1
>>... do something with oCurrent ....
>>
>>o1.next = createobject("my_object")
>>oCurrent = o1.next
>>... do somethig with oCurrent ....
>>
>>&& now I try to release to objects
>>release oCurrent
>>release o1
>>
>>My questions are:
>>1. does oCurrent = o1.next copy the object or just the reference of the object?
>
>A reference is copied. Any change done on one variable will be seen as changes in the other variable.
>
>>2. does release oCurrent release the memory acquired in 2nd createobject?
>
>I understand an object gets destroyed as soon as there are no references to it:
>
>
>o1 = CreateObject(...) && Object created (and Init() fired), one reference to object
>o2 = o1 && Second reference to the same object
>release o1 && Still one reference to object
>release o2 && No reference to object; object gets destroyed, Destroy() is called.
>
>
>I seldom release objects explicitly; note that when an object variable gets out of scope, the object gets destroyed (if there are no more references to it). However, in some situations there are cross-references that avoid objects from being destroyed ("dangling object references"). This will usually happen with properties of an object, that have a reference to another object. In this case, you can assign NULL to the property, as part of the cleanup process.
>
>>3. does release o1 release the memory for both createobject(...) even without the release oCurrent?
>
>As long as there are references to an object, the object remains in memory.

Thanks for the response. Do you mean as long as an object gets no reference it will be released? If yes, then when the garbage will be collected?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform