Eliot Miranda pisze:
On Sun, Jul 29, 2012 at 7:56 AM, Mateusz Grotek unoduetre@poczta.onet.plwrote:
Hi I have the following 3 questions:
- Why there is ContextPart>>releaseTo: ? What will happen if I don't
use it?
releaseTo: simulates the effect of doing a method return from a block, i.e. when a return exits more than the top context. It sends singleRelease to each context exited, which sets the pc and sender to nil (and nils the stack, but this is excess to requirements). releaseTo: is actually used when a method return from a block encounters an unwind-protect and control passes up to the image to run the unwind. You don't need to use it. It is used automatically as part of running unwinds. In what situation do you think you do need to use it?
I'm trying to implement backtracking as described in the paper: "Building a backtracking facility in Smalltalk without kernel support" by W. LaLonde and M. Van Gulik
They commented their use of releaseTo: in this way:
"aContext releaseTo: oldContext Release (by setting the temporaries in the context stack to nil) all contexts from the receiver, its sender, its sender's sender etc. up to but excluding oldContext. It is a superflous method that helps the garbage collector."
I wondered if this is an artifact of the version of Smalltalk they used when writing the paper, or it really helps the garbage collector in some way. As far as I understand it contexts are collected just like normal objects, when there are no references to them. So i don't see a point in using this method, but I'm not an expert and maybe i miss something, so I asked this question.
Thank you for the anwer.