smith@canon.co.uk (Mark Smith) (05/09/91)
Does anyone else have trouble reconciling the description of garbage collection in NeWS/TNT with reality? From the TNT manual (I'm using TNT 2.0 beta), ClassCanvas, pages 69/70: "When the last hard reference to an object is broken, the object is sent the obsolete message ... TNT catches the obsolete event and sends /destroy to the object ... You never need to call /destroy on any object you create." I've been playing with some very simple classes to make sure that my understanding of how the garbage collection works is correct, but even the simplest classes seem to behave other than what I'd expect. For instance, here's a minimal class definition: /SimpleClass [ ClassObject ] nulldict classbegin /NewInit { console (NewInit %\n) [ self ] fprintf /NewInit super send } def /destroy { console (destroy %\n) [ self ] fprintf /destroy super send } def classend def Now, let's say I create an instance of this in a psh. I see the NewInit message in my console. Now if I pop the object off the stack, shouldn't I see the destroy message? I don't. I see the same behaviour with more real-world examples - for example, create a ClassBaseWindow instance, then add a client canvas to it as /Center, then remove the client. The client canvas is left on the stack and refcnt says that there are no references left, yet /destroy never seems to be called. Also, if you look at the code that implements ClassWindow, you'll see that it explicitly calls /destroy on all its subwindows. Does anyone understand all this stuff, in the context of what I quoted up at the top of this article? [ Mark Smith Canon Research Europe -- smith@canon.co.uk ..ukc!canon!smith ]
siegel@sun.com (Josh Siegel) (05/11/91)
> In article <1991May9.161618.13057@canon.co.uk> smith@canon.co.uk (Mark Smith) writes: > > [...] > > Does anyone else have trouble reconciling the description of > garbage collection in NeWS/TNT with reality? From the TNT manual > (I'm using TNT 2.0 beta), ClassCanvas, pages 69/70: > > [...] > Destroy is only called when there are soft references to the object. --josh == /ClassFoo ClassObject [/me] classbegin /NewInit { console (I am alive!\n) fprintf /NewInit super send } def /set_self { /me self soften def } def /destroy { console (I am dead!\n) fprintf /me unpromote /destroy super send } def classend def /new ClassFoo send dup /set_self exch send pop