This.oObject.Release() > Release This.oObject > This.oObject = .Null.>Are these all equivalent?
Define class TheClass as Relation Instance = '' OtherObject = null function init(instance) this.Instance = m.instance return DoDefault() endfunc function Destroy() acti screen ?'Destroy ', m.this.Instance endfunc function Release() release this endfunc enddefine
*_______________________________________________________________________________ function TestDestroy1() local obj1, obj2, obj3 obj1 = createObject('TheClass', '#1') obj2 = createObject('TheClass', '#2') obj1.OtherObject = m.obj2 release obj1, obj2 && Destroy #1 && Destroy #2 endfunc
function TestDestroy2() local obj1, obj2, obj3 obj1 = createObject('TheClass', '#1') obj2 = createObject('TheClass', '#2') obj2.OtherObject = m.obj1 release obj1, obj2 && Destroy #2 && Destroy #1 endfuncIf you have a circular reference, you may have a problem
function TestDestroy3() local obj1, obj2, obj3 && Circular reference obj1 = createObject('TheClass', '#1') obj2 = createObject('TheClass', '#2') obj3 = createObject('TheClass', '#3') obj1.OtherObject = m.obj2 obj2.OtherObject = m.obj3 obj3.OtherObject = m.obj1 release obj1, obj2, obj3 && no object is being destroyed && need to use :Clear all endfuncobject.Release() forces the object's reference count to become zero
function TestDestroy4() local obj1, obj2, obj3 obj1 = createObject('TheClass', '#1') obj2 = createObject('TheClass', '#2') obj3 = createObject('TheClass', '#3') obj1.OtherObject = m.obj2 obj2.OtherObject = m.obj3 obj3.OtherObject = m.obj1 =m.obj2.Release() && Destroy #2 ?obj2 && Null ?obj1.OtherObject && Null : obj1.OtherObject is null because it has been destroyed && Destroy #3 && Destroy #1 endfunc