
Signature
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
<snip>
> Well, that's actually a different question from the one you originally
> asked, and it has a slightly more positive answer. If you just want
> methods that are not reachable at all except through your list (which is
> quite different from wanting objects that aren't referenced by named
> variables in the root set), then java.lang.ref.WeakReference might be
> able to help.
Can you elaborate? I don't understand the difference.
> There are still some limitations: you can't ask for the full set of
> otherwise unreferenced object at just any point; you have to wait for
[quoted text clipped - 4 lines]
> you check out the API docs for WeakReference, and perhaps also
> ReferenceQueue, in the java.lang.ref package.
Thanks again for the help. No, I'm not worried about performance
issues. Just explaining why the blue object can no longer be
controlled but is still on the screen, etc.. Actually, this may be a
good thing as it can lead into a discussion of reassignment, the
garbage collector, and objects in general.
> On a parallel note, though, it's always best to at least plan for the
> possibility that people will use your API safely; so please consider
> providing a way for the student to remove an object that they *know* is
> no longer used, rather than waiting for the garbage collector to find
> and remove it. Perhaps you can teach some concepts about resource
> management at the same time.
I'd planned on using my library to primarily teach the basics: if's,
loops, subclassing, overloading, overriding of methods etc.. But
throwing in some fundamentals of resource management can't hurt
either.
I'll have to look through the WeakReference API. None of their
programs will probably run long enough for the gc to run, but if one
did, having the "orphan" object eventually disappear might help the
kids understand the idea of the gc running in the background.
Thanks again for your help.
tom
Chris Smith - 30 Nov 2003 05:10 GMT
> Chris Smith <cdsmith@twu.net> wrote...
> <snip>
[quoted text clipped - 6 lines]
>
> Can you elaborate? I don't understand the difference.
Sure. You were (apparently) asking for objects that aren't referred to
by named variables from some context; I'm talking about objects that are
unreferenced from anywhere that's reachable, however indirectly.
> > There are still some limitations: you can't ask for the full set of
> > otherwise unreferenced object at just any point; you have to wait for
[quoted text clipped - 10 lines]
> good thing as it can lead into a discussion of reassignment, the
> garbage collector, and objects in general.
Oh! If it's a visible effect, then forget WeakReference, and you need
to teach students to clean up after themselves. At least it looks like
it'll be obvious if they don't.
> I'll have to look through the WeakReference API. None of their
> programs will probably run long enough for the gc to run, but if one
> did, having the "orphan" object eventually disappear might help the
> kids understand the idea of the gc running in the background.
Actually, at the level you're working at, please do them a favor and
don't start trying to talk about when objects are claimed by the garbage
collector. As I said a few weeks ago, the *only* sensible model for a
beginning programmer is to count on objects always being there and
pretend they exist until the end of time. Only when specifically
dealing with performance issues should anyone be concerned about when
the garbage collector runs. It doesn't sound like your students are
going to be doing performance optimization, so why confuse them?

Signature
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation