Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is best cyclic graph representation to be kind to Java GC

Or I might ask with newer GCs does it matter?

If it does then is it desirable to manage links between nodes through a lookup table or using weak references ( yet more memory ), or is it fine just to have all the nodes point to each other. This is assuming I have a "dispose" method where node or link removal sets all references to it to null.

The issue is if there is a large database in ram, would it be a drastic hit on GC performance if it has to evaluate a lot of long random cycles in the graph? or not?

like image 944
peterk Avatar asked Dec 05 '25 04:12

peterk


1 Answers

The mark and sweep approach to garbage collection is totally insensitive to the topology of object graphs. As soon as it reaches an already marked object, it assumes all its referents are marked as well, so you can't do much harm no matter how you design your structure.

My advice is to be obsessive about keeping your code as natural a fit to the problem as possible, and quite lax about any other concerns. When you hit a real performance/memory problem, only then comes a time when you stop and think about optimization.

like image 177
Marko Topolnik Avatar answered Dec 07 '25 17:12

Marko Topolnik