On 10/12/2018 09:26 AM, Stanislav Blinov wrote:
On Thursday, 11 October 2018 at 21:22:19 UTC, aberba wrote:
"It takes care of itself
-------------------------------
When writing a throwaway script...
...there's absolutely no need for a GC. In fact, the GC runtime will
only detract from performance.
Throwaway scripts can allocate a lot of memory and have nontrivial
running times. It's less common for scripts than for long-running
processes, granted, but I've written scripts to go through gigabytes of
data.
What this means is that whenever I have disregarded a block of
information, say removed an index from an array, then that memory is
automatically cleared and freed back up on the next sweep. While the
process of collection and actually checking
Which is just as easily achieved with just one additional line of code:
free the memory.
People demonstrably have trouble doing that. We can do it most of the
time, but everyone occasionally forgets.
Beyond that, the concept you're failing to mention here is ownership.
You need to use your own mental effort to figure out what memory is
owned by what part of the code. The GC lets you ignore that.
Don't be a computer. Do more with GC.
Writing a throwaway script there's nothing stopping you from using mmap
or VirtualAlloc. The "power" of GC is in the language support for
non-trivial types, such as strings and associative arrays. Plain old
arrays don't benefit from it in the slightest.
A string is a plain old array, and languages with manual memory
management also support associative arrays.