This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
Can I set var metadata dynamically ?
So I can I do the following using intern ?
(def ^{:doc "The clojure doc for row-count"
:arglists [['dataset-or-ctx]] } row-count (lift tc/row-count))
In which the metadata
is a normal map ?How does structural sharing work with garbage collection? For example, how does the garbage collector know to only collect parts of an object when I dissoc from a map?
parts of an object are also objects, so my understanding is that GC can collect unreachable nodes. A linked list is maybe the easiest one to visualize... if there's a three-node list, and a new list which conses on to the front, that first node can get GC'ed if the new list goes out of scope/becomes unreachable.
In general, a full GC implementation starts from "root objects" of your program, and determines all objects reachable through references/pointers in one or more other objects starting at those roots. Any object that cannot be reached is "dead" and subject to collection. Any object that can still be reached through some path from a root is "live".
TBH, list is a simple example. But I suppose persistent datastructures need careful considerations because even if the user-accessible "value" may go unreachable, the update/modify algorithms need to be careful not to keep references to the "discarded" parts.
it is a funny fact that GC is more concerned about live objects than it is about garbage.
When you can have cycles in the references/pointers of data structures, as Java allows (as do most general purpose programming languages that have references/pointers), it seems pretty tricky to me to even define what garbage means, except as "not live".
If your references/pointers are restricted to be acyclic, you can implement memory management precisely with reference counters to objects, which gives you another precise way to define when something is garbage, but that doesn't work when cycles are allowed.
That's a good observation. The fact that there are like what, 3 other types of references. Like Soft, Weak, Phantom if not more that I'm not aware of 😅
Oh, right. I wasn't even factoring those kinds of references in to my comments above. Everything above I was thinking only of "strong" references.