I'd think you'd need something like Cocoa's autorelease pool or
something...
The problems are severalfold:
1) You need a container class somewhere to hold references to your
object variables (note: not references to the objects these variables
point to!) so that - later - you can nil them all out.
The problem is that RB doesn't have the '&' operator of C++, like:
typedef MyClass *MyClassPtr;
void blahblah(void)
{
MyClassPtr b = new MyClass;
MyClassPtr &myClassPtrRef = b;
...
}
in the above, 'myClassPtrRef' can modify 'b' at any time, even if
it's passed around from function to function. So if the code above
had an array of MyClassPtr & instances, that tracked all the
instances of MyClassPtr floating around, it could later 'delete' and
'nil' them.
2) You'd need to tightly control the lifetimes of the objects in said
container so that extras don't get created, nor instances released
without notice.
The problem here is that; 1) you'd need to override the assignment
operator, and 2) you'd have to override the "New" operator, 3) you'd
have to modify any copy constructors or copy/clone methods (shallow
or deep).
3) You'd need to supply a factory method that added the reference-to-
object-variables into the container before handing your client code
the new reference-to-object in the object variable.
The only reasonable way I can see to do this in RB is to wrap
class A (where class A is a class whose instance variables you want
weak references to) in a class B, then dispense instances of class B
from a factory method in a module somewhere that would add copies of
the class B instances into a collection of some sort. The module
would also provide a 'KillAll()' method that would iterate over the
container of B objects and set their <reference-to-class-A> variables
to nil, meaning either you'd have to expose that property as Public,
or make a Sub/Function pair or computed property that was Public, as
RB doesn't have the concept of friend classes. Your client code would
operate with the class A instances through the class B instances
(objects) as desired.
Think of it as being analogous to what you'd have to do to write a
Swap(ByRef i As Integer,ByRef j As Integer) method, but without the
benefit of a "ByRef" keyword! (i.e. you'd have to wrap an integer in
a class, then pass the object references in.)
On Feb 13, 2007, at 6:47 PM, Norman Palardy wrote:
On Feb 13, 2007, at 5:41 PM, [EMAIL PROTECTED] wrote:
I know that a RB will destroy objects with no references
remaining, but is it possible to force an object to get destroyed,
even if there are multiple references to it?
You have to get rid of all the references by nil'ing them or having
the objects holding the references go out of scope
There's no "kill this object"
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>