> This is a difficult one, unless...
> 
> In RBScript having a class say:
> 
> class RBScriptObject
>       private dim instanceSig As Integer
> 
>       sub Constructor(name As String, className As String, address As String) 
>         
>               numberOfObjects = numberOfObjects + 1
>               instanceSig = numberOfObjects
>               gObjectArray(instanceSig) = self
>       end sub
> 
>       sub Destructor()
>               numberOfObjects = numberOfObjects - 1
>               gObjectArray(instanceSig) = nil
>               instanceSig = 0
>       end sub
> end class
> 
> and global variables:
> 
> dim gObjectArray(100) as RBScriptObject
> dim numberOfObjects As Integer = 0
> 
> If the script is generating a number of local instances of the class and a 
> bunch of them go out of scope, the destructor of the class gets called, but 
> not in this example, because the gObjectArray holds a reference to it. 
> Because it is in RBScript, I have no idea how to make the array not to add a 
> ref to it, can't use REALUnlockObject, and looking in the language ref about 
> Weakref (which is unclear!), and noting that RBScript does not know anything 
> about WeakRef, I am at loss how to find a way to let the destructor fire, 
> other than not using an array...

The problem is your code, not RBScript. Your code doesn't make sense whether it 
was in RBScript or normal RB!

Why did you write this?

        sub Destructor()
                numberOfObjects = numberOfObjects - 1
                gObjectArray(instanceSig) = nil // THIS LINE HERE MAKES NO SENSE
                instanceSig = 0
        end sub

How can this destructor ever occur if there is a reference to that object still 
existing? A refernce that the destructor itself was supposed to clear? It's a 
"Catch-22" problem.

Maybe you need something like this.

sub Dispose() 
        numberOfObjects = numberOfObjects - 1
        gObjectArray(instanceSig) = nil // THIS LINE HERE MAKES NO SENSE
        instanceSig = 0
end sub

sub Destructor()
        Dispose()
end sub

This way, you must manually call MyObject.Dispose() to get rid of it.

--
http://elfdata.com/plugin/
"String processing, done right"



_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to