When you schedule something, the schedule (or the SimState's mini-
schedule) holds onto that object until its event time has come up.
Sometimes this isn't desirable. For example, imagine if you wanted
to schedule a window to be updated at a certain time, but someone
might close the window before this time occurrs and you need to have
the resources released. You can do this by wrapping the steppable in
a WeakSteppable, schedule the WeakSteppable, and then store the
steppable in some instance variable in the window. If the window is
closed, the only thing left pointing to the window is the steppable.
And the only things left pointing to the steppable are the window and
the WeakSteppable holding the steppaable. Since the WeakSteppable's
reference to the steppable is weak, this means that the window and
the steppable are the only things *really* left pointing to each
other. Which means they're candidates for garbage collection.
When they get garbage collected, the WeakSteppable's reference
magically becomes null. When the schedule later calls the
WeakSteppable, nothing happens (because there's no window left).
This relies on the notion of Weak References, a concept introduced in
Java 1.3 which you may want to read up on a bit for more info.
On Oct 25, 2007, at 7:34 PM, Alan Thomas wrote:
> I read about "schedule weakly," but I`m still not completely sure I
> understand it. Could someone explain it?
> Thanks, Alan