Thread View: news.software.nntp
1 messages
1 total messages
Started by Lionel W. Penton
Mon, 12 Mar 2007 00:25
Re: forcing finalize()
Author: Lionel W. Penton
Date: Mon, 12 Mar 2007 00:25
Date: Mon, 12 Mar 2007 00:25
91 lines
4362 bytes
4362 bytes
In article <45ce0e0d$0$49206$14726298@news.sunsite.dk>,
=?ISO-8859-1?Q?Arne_Vajh=F8j?= <arne@vajhoej.dk> wrote:
>nukleus wrote:
>> Btw, I just read some posts on memory allocation/deallocation issues,
>> and I did not quite expect the behavior described.
>>
>> I thought that object is gc'ed when there are no references left.
>
>Java does not use reference counting.
>
>Objects that are not reachable from the executing program can be
>GC'ed.
Interesting. But how do they know they are not reachable?
>> So, if i have a multi-variable object, containing strings,
>> buffers, etc. and I put those objects in a Vector,
>> for the sake of argument, and, i do setElementAt() and set
>> it to null, i thought it becomes a subject to gc,
>> and, once it is gc'ed, all the buffers, strings, etc.,
>> it contains become subject to gc also.
>
>The GC can/should GC them all in one sweep.
Thanks god.
>> Secondly, if i have a string and then set it to a new value,
>> does the old value become a subject to gc?
>
>Yes.
>
>> Sting s = "abc";
>> s = "def";
>
>There are some special handling for string literals where Java
>only have one object for the same literal.
Well, i didn't mean string literal,
but string as such.
>> What happens to "abc" string in terms of deallocation?
>> Is it the same as new String("def")
>> meaning that there is no longer a reference
>> to "abc" and it, therefore, is subject to gc?
>Ignoring the special handling of String literals, then
>as soon as there are no way to reach an object it can be GC'ed.
Sorry, but I don't get it.
How does it know it can't reach something?
>> How do I release memory held by StringBuffer?
>
>Just let the reference run out of scope.
Well, but when I am in a loop, reusing the same string
buffer that has large amounts of buffer for each iteration,
what happens to the old data?
Should I just create a new buffer every iteration
just to make sure the old stuff gets gc'ed?
I am talking about 10s of megs of data being shuffled.
>> When I set its size to 0 and start accumulating
>> a new data in it, what happens to the old data?
>> Is it gc'ed?
>
>Depends on the implementation. You can look it up whether
>it reuses the backing storage or not. I have not checked
>it out myself. You should not code after that kind of
>implementation issues.
Thanks.
>Arne
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
On Purim, Feb. 25, 1994, Israeli army officer
Baruch Goldstein, an orthodox Jew from Brooklyn,
massacred 40 Palestinian civilians, including children,
while they knelt in prayer in a mosque.
Subsequently, Israeli's have erected a statue to this -
his good work - advancing the Zionist Cause.
Goldstein was a disciple of the late Brooklyn
that his teaching that Arabs are "dogs" is derived
"from the Talmud." (CBS 60 Minutes, "Kahane").
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads