Re: Question from a newbie
Drew Dean <[email protected]> Wed, 07 May 2003 08:19:36 -0700 (PDT)
| Newsgroups | gmane.comp.programming.garbage-collection.general |
|---|---|
| Message-ID | <[email protected]> |
From: "Wang, Daniel Chen-An (Dan)" <[email protected]> Subject: Re: [gclist] Question from a newbie Date: Wed, 7 May 2003 10:49:49 -0400 > In practice "data which is not reachable" begs the question of what should > be reachable! > > For example: > void m1() { > Object obj1 = ...; > Object obj2 = ...; > m2(); > return obj2; > } > > void m2() { > /* gc gets invoked */ > } > > When m2 is called an the gc is invoked is obj1 reachable? Well that > depends on whether or not the compiler spilled the obj1 variable on the > stack or nulled out it's register holding the value. Intuitively obj1 is > garbage, because we don't touch it after we return from m2. In fact a good > compiler should sprinkle enough information in the stack frames so that > even though obj1 may be on the stack the GC doesn't trace it. Obviously, > the compiler and the programer have a more interesting "semantic" > definition of what is and isn't "garbage". This notion of "garbage" is not > at all tied to reachablity. Hi Dan! How's Agere? I'm not sending this to the list to prevent a flame war, but if I can pick a language to instantiate your program, let's consider C++, and Object obj1 = new WaitCursor(); relying on the destructor at the end of m1 to restore the normal cursor, which, oh by the way, keeps an "invisible" (at the source code level) reference around. I don't much like C++, but friends who use it praise this paradigm. I think we agree: the notion of what's garbage can get quite involved! Drew