Re: general performance question
Mike Schilling wrote:
"Knute Johnson" <nospam@rabbitbrush.frazmtn.com> wrote in message
news:47a24c4b$0$1538$b9f67a60@news.newsdemon.com...
Mike Schilling wrote:
I don't think that is true. If you create an Object in a loop and
then reassign another Object to the same reference in the loop, the
first Object is eligible for garbage collection (and will be).
The previous poster didn't mention loops, merely a nested block
scope.
For a loop, the value set in the last iteration also leaks the
block.
/L
How can it if the reference is created in the block?
The method's stack frame isn't collected until the method exits; it has
no notion of block scope.
public void method() {
Object oy = new Object();
do {
Object o = new Object();
} while (false) ;
// do other stuff
}
So I think we are talking about two different things here. o's objects
are created on the stack but go out of scope at the end of the do loop.
The "name" goes out of scope. The slot in the method stack frame that
corresponds to "o" is just another slot, exactly as if this had been written
public void method() {
Object oy = new Object();
Object o = new Object();
// do other stuff
}
That is, block scopes within a method exist at compile-time, but not at
run-time.
In your code snippet above, the objects that oy and o reference can be
GC'd when method() is exited. Are you saying that they can't? The same
would hold true for the references oy and o as well.
In the example where an Object is created in a loop and the reference is
created inside the loop, the Object can be GC'd as soon as there is no
reference to it even inside the loop. I would assume that setting the
reference to a object to null would also allow the original object to be
GC'd although I'm not sure how to demonstrate that. It is very easy to
demonstrate garbage collection in a loop.
--
Knute Johnson
email s/nospam/knute/
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access