Sender: |
|
Date: |
Thu, 25 Oct 2007 19:51:33 -0400 |
MIME-version: |
1.0 (Apple Message framework v752.3) |
Reply-To: |
|
Content-type: |
text/plain; charset=US-ASCII; delsp=yes; format=flowed |
Subject: |
|
From: |
|
In-Reply-To: |
|
Content-transfer-encoding: |
7bit |
Comments: |
|
Parts/Attachments: |
|
|
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.
Sean
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
|
|
|