3 ms·
The examples seem like they would consume a lot of memory, since every update allocates a new object to the heap. Java's garbage collection solves this, but do
by Cieplak 11y ago
The examples seem like they would consume a lot of memory, since every update allocates a new object to the heap. Java's garbage collection solves this, but does anyone know of an annotation or method to use to mark the old object as unused so the runtime can deallocate the old object as soon as the new object is created, rather than waiting for a stop-the-world gc pause? I guess a better way to handle this would be to return a new object with most of the attribute references unchanged, besides the updated fields.
- Cieplak 11y agoTo attempt to answer my own question about marking objects for deletion, it seems like there aren't a lot of options besides making sure there aren't outstanding references to the dead object: http://stackoverflow.com/questions/11332239/is-it-possible-to-mark-java-objects-non-collectable-from-gc-perspective-to-save http://stackoverflow.com/questions/11332239/is-it-possible-t... http://stackoverflow.com/questions/5331422/marking-an-object-to-be-removed-in-the-gc http://stackoverflow.com/questions/5331422/marking-an-object...
- bobm_kite9 11y agoSo, rather than reinvent the wheel, I just ported the Clojure collections over, added generics and made them more Java-ery [1] In the Clojure world, (and indeed in Haskell and other pure-fp languages) there is a lot more garbage collection. Rich Hickey makes a great case for this trade off here [2]. On the JVM now very little of it is stop-the-world GC, it mostly does incremental. It's been a while since I profiled a Java app in anger, but even back on JDK5 this was the case, and I know they changed it significantly in JDK7 to the G1 collector.. anyone have a clue about that? [1] https://github.com/robmoffat/pure4j/blob/master/docs/tutorial_collections.md https://github.com/robmoffat/pure4j/blob/master/docs/tutoria... [2] http://www.infoq.com/presentations/Value-Values http://www.infoq.com/presentations/Value-Values [3] http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/G1GettingStarted/index.html http://www.oracle.com/webfolder/technetwork/tutorials/obe/ja...