
Baby’s First Garbage Collector (2013) - pcr910303
http://journal.stuffwithstuff.com/2013/12/08/babys-first-garbage-collector/
======
youdontknowtho
This is awesome. I'm working my way through The Garbage Collection Handbook
and it's always nice to see a GC link on HN.

"What does “low on memory” even mean, especially on modern computers with
near-infinite virtual memory?" is a question that I've been wondering about
for a while.

~~~
tempguy9999
If you mean the jones/lins book, it's excellent[0]. Fully recommended to all.

[0]
[https://www.amazon.co.uk/gp/product/0471941484](https://www.amazon.co.uk/gp/product/0471941484)
I think there's a 2nd edition but I can't find it.

~~~
mangamadaiyan
> 2nd edition but I can't find it

Perhaps you're referring to this one [1]?

[1] [https://www.amazon.co.uk/Garbage-Collection-Handbook-
Managem...](https://www.amazon.co.uk/Garbage-Collection-Handbook-Management-
Algorithms/dp/1420082795/)

~~~
tempguy9999
Thanks, I think I was confusing that with the 2nd ed, which doesn't seem to
exist (in fact there is a 1999 2nd _printing_ of the 1996 book with a
different cover but with the same ISBN, just to make things worse,
[https://www.cs.kent.ac.uk/people/staff/rej/gc.html](https://www.cs.kent.ac.uk/people/staff/rej/gc.html),
so if you want to buy the later one which incorporate the errata from the
first printing, check his website first. Publishers do make a mess of things
sometimes).

Jones' website
[https://www.cs.kent.ac.uk/people/staff/rej/gc.html](https://www.cs.kent.ac.uk/people/staff/rej/gc.html)
is excellent too.

------
sdegutis
From the same guy:
[https://craftinginterpreters.com](https://craftinginterpreters.com) great
stuff

------
mikorym
Reach-ability in graphs is quite an interesting topic in applied sciences.

For example, recently I had to figure out (nontrivial) investment proportions
in funds and realised two things:

1\. You can use a weighted DAG [1] and sum the products of paths from each
leaf to the root to get to the investment proportions; the total of all such
paths from leaves to the root should be 100% of the underlying investing
entities.

2\. Tax offices should use weighted DAGs to figure out cases where there is
suspected fraud. Whenever you sum and don't get to 100%, then you know that
people are doing fishy things with their investment vehicles and shell
companies. [2]

[1] [https://en.wikipedia.org/wiki/Daw](https://en.wikipedia.org/wiki/Daw)

[2] [https://en.m.wikipedia.org/wiki/CumEx-
Files](https://en.m.wikipedia.org/wiki/CumEx-Files)

~~~
mikorym
Sloppy, really.

[1]
[https://en.wikipedia.org/wiki/Directed_acyclic_graph](https://en.wikipedia.org/wiki/Directed_acyclic_graph)

------
rkangel
Discussion from 2013:
[https://news.ycombinator.com/item?id=6871202](https://news.ycombinator.com/item?id=6871202)

------
peterwwillis
I'm no great programmer, so my stupid question of the day is: why do people
depend on GC so much? Garbage collection is one of those weird things that
everyone seems to accept must be necessary in higher level languages, and end
up being quite a burden in operation. The more people depend on dynamic
memory, the more likely GC problems are. Meanwhile, the simplest fix in the
world - restart the process frequently - prevents memory leaks from
accumulating, and requires no complicated tuning.

~~~
stormbrew
> Meanwhile, the simplest fix in the world - restart the process frequently -
> prevents memory leaks from accumulating, and requires no complicated tuning.

This is just a degenerate case of garbage collection, really.

~~~
tempguy9999
A novel and valid perspective.

I have simply relied on leaking wildly before, knowing it's a small program
that will end soon. It's an acceptable solution in some cases.

~~~
LadyCailin
The JVM now has the epsilon GC, which does basically that, it just never GC’s.
It’s unfortunate though that there’s no explicit way to tell java to free up a
certain reference, if so, in combination with epsilon, you could write real
time programs. Maybe you already can do something like that in the embedded
java version though? Not sure.

~~~
tempguy9999
Interesting. First I've heard of it. Well I guess if you can ensure bounded
space by limited allocaton, then simply shove manually 'freed' stuff back on a
free list, you could do that, sure.

But a quick google gets
[https://openjdk.java.net/jeps/318](https://openjdk.java.net/jeps/318) which
does say

    
    
      Non-Goals
      It is not a goal to introduce manual memory 
      management features to Java language and/or JVM...
    

but it doesn't say you can't or shouldn't. Game on then.

~~~
LadyCailin
Sure, if all your objects are mutable, then that can work, but a lot of stuff
in core libraries are not, and you can’t control those allocations, short of
not using them. There is also sun.misc.Unsafe, which has freeMemory, but first
of all, I don’t know if that works for arbitrary addresses, or just ones
previously allocated from the allocateMemory method, and anyways, I don’t
think there’s a reliable way to get the address of an arbitrary object in the
first place. But to add both of those pieces of functionality should be a
pretty small patch to the jvm code anyways, so if someone were really
motivated, it may not be all that much work anyways.

~~~
tempguy9999
> and you can’t control those allocations

You're totally right. Rather stupidly I hadn't thought of that.

