On 06.01.2009, at 20:48, Igor Stasenko wrote:
2009/1/6 Séverin Lemaignan skadge@gmail.com:
Hello,
I would like to execute some code (closing a serial port) when a morph is destroyed by an user (either by clicking on the cross or by drag&dropping the morph to the bin). Do you know how to do that?
You could override #delete.
Use finalization for closing any external resources being used by squeak-based objects.
Finalization should be used only as a last measure to avoid leaking system resources. It can take a very long time from the point where an object becomes unreachable until it is finalized.
As a bonus question, is it possible to detect, on the contrary, when a morph is restored from the bin (to reestablish the communication) ?
Implementing #intoWorld: and #outOfWorld: should work (instead of putting this into #delete).
- Bert -