Re: Controlling the Garbage Collector
On 25.06.2012 19:45, Eric Sosman wrote:
On 6/25/2012 1:01 PM, Andreas Leitgeb wrote:
Maybe slightly more interesting questions:
What would be the behaviour of that proposed call,
- if "old" *is* still (hard-)referenced from live objects?
- if there's still a weak/soft-reference on that object?
(pick one: Exception, force(for weak/soft-refs) or ignore?)
Exactly: The JVM could not simply trust the System.gc(obj)
call to be telling the truth, because that would open the door
to all manner of attacks.
Not just attacks but simple errors as well.
Therefore the JVM would have to verify
that obj was unreachable (at whatever strength) before deciding
to dispose of it. That is, the JVM would have to run nearly all
of the garbage collector to determine obj's reachability -- so
why not just run the ordinary GC in the ordinary way? I'm at a
loss to imagine what benefit a System.gc(obj) would offer.
I had exactly this kind of reasoning in mind when I said:
I once mused about such a thing as well. If you think a bit longer
about this then you'll notice that it won't work: these objects still
have to be visited because they may have references to other objects
not in the uncollectable space. You'll probably do not gain much -
if anything at all.
Thank you for the elaboration, Eric and Andreas! I think a non uniform
object memory model (e.g. some GCed, some manually managed) cannot get
rid of the GC overhead even for the manual kind as long as it is allowed
to have references between the different kinds of objects. Disallowing
that however would make the distinction visible and you end up with a
language with a non uniform object model. That would certainly make
programmers' lives harder instead of easier.
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/