On Friday, 7 January 2022 at 20:40:02 UTC, Adam D Ruppe wrote:
On Friday, 7 January 2022 at 20:33:05 UTC, eugene wrote:
* python guys have memory leaks
* js guys have memory leaks

GC isn't actually there to prevent memory leaks.

Aha, unless you'll build GC into OS core :)

Its main job is to guard against use-after-free memory corruption bugs


```c
if (ptr) {
    free(ptr);
    ptr = NULL;
}

...

    if (NULL == someptr)
        BUG()/PANIC()/WHATEVER()
```

because computers don't have infinite memory

first time I've heard this )))
tell that to py/js super-coders :)

where the lifetime is trivial, you can easily do it yourself to optimize memory use. But when it isn't so obvious, you can use the GC to play it safe at the cost of a lil more memory use.

other way around

* when the lifetime is trivial (whithin a function, including thread function) - trust GC * when the lifetime is not trivial (ptr goes through or a self-pipe or similar) - GC has no info about that


Reply via email to