3 ms·
Isn't that what garbage collection essentially is?
by RiverCrochet 2y ago
Isn't that what garbage collection essentially is?
- OutOfHere 2y agoGarbage collection doesn't impose a subjective reasonable vs unreasonable time limit for holding memory. It checks if the memory is still in use or not. Garbage collection is never subjective; it is entirely objective and without ambiguity or bias with regard to the guarantees it offers.
- eesmith 2y agoEarlier you wrote "Let's invent a new programming language that tells its users that the amount of time for which they hold memory should be "reasonable", without getting into specifics." This is essentially what Python-the-language does. It does not require reference counting, or mark-sweep, or any garbage collection at all. The language specification says at https://docs.python.org/3/reference/datamodel.html#objects-values-and-types https://docs.python.org/3/reference/datamodel.html#objects-v... : "Objects are never explicitly destroyed; however, when they become unreachable they may be garbage-collected. An implementation is allowed to postpone garbage collection or omit it altogether — it is a matter of implementation quality how garbage collection is implemented, as long as no objects are collected that are still reachable." That subjective language specification is quite different than its objective implementation in a Python implementation, which appear to be what you refer to now.
- nox101 2y agoI'm not sure of your definition of objective here. If you mean a specific implementation and exact version of a specific language does one objective thing that might be true. But, different implementations of the same language and different versions of those implementations can all do different things. GC rarely says exactly when something will be collected. Only that it will eventually. Example: https://jsfiddle.net/8cej4tpk/2/ https://jsfiddle.net/8cej4tpk/2/ Firefox GCs after about 8 seconds, Safari GCs immmediately, Chrome never (probably not until there's pressure). And, you'll find different behavior if you go check different versions of those browsers.
- OutOfHere 2y agoApologies, but the point was that a GC will never unjustly take your memory from you without a well-defined rule. It may delay in taking it away, but if it does, it will be very clear why it did.
- kbolino 2y agoThis claim is false for a lot of modern language runtimes which use tracing garbage collection, like the CLR (C#/VB), JVM (Java/Kotlin/Scala/etc), Go, BEAM (Erlang/Elixer), etc. There are no hard promises about when or even whether GC will reclaim a particular piece of garbage, precisely to enable optimizations and necessary compromises. Application availability is often more important than immediately collecting every possible piece of garbage. The use of tagging, generations, arenas, etc. all allow the GC to use heuristics and apply different collection regimes to different pieces of garbage.
- OutOfHere 2y agoApologies, but I meant it terms of the guarantees that a GC offers. Yes, the GC can delay, but it will never over-eagerly reclaim beyond its advertised guarantee. It will always err on the side of not reclaiming.
- ffgjgf1 2y agoSo exactly the same as saying that you will get your money back at some undefined point in the future whenever the police agency you’re dealing it will find it convenient?
- OutOfHere 2y agoNo, rather that your money (memory) will never be taken away from you (your application) by the police/system (runtime/OS) without an objective rule.