Implement a basic GC based on the mark-and-sweep algorithm, without requiring manually specifying "roots", which vastly simplifies the management. For now, it is triggered every 30 seconds since it last finished, on a new object initialization. Better heuristics could be used in the future.
The comments in the code should hopefully understand the high level logic of this approach without boilerplate details. I've tested it on FFXIV launcher (along with other patches from Proton to have it work) and it stops the massive memory leak successfully by itself, so at least it does its job properly. The last patch in the MR is just an optimization for a *very* common case.
For artificial testing, one could use something like:
```javascript
function leak() {
var a = {}, b = {};
a.b = b;
b.a = a;
}
```
which creates a circular ref and will leak when the function returns.
It also introduces and makes use of a "heap_stack", which prevents stack overflows on long chains.
--
v3: jscript: Create the source function's 'prototype' prop object on demand.
jscript: Run the garbage collector every 30 seconds on a new object
jscript: Implement CollectGarbage().
jscript: Implement a Garbage Collector to deal with circular references.
https://gitlab.winehq.org/wine/wine/-/merge_requests/1635
Not completely sure if it's worth having for 8.0, but opening this to share the target I'm trying to reach.
--
v2: ntdll: Implement Low Fragmentation Heap.
ntdll: Introduce per-thread free lists for heap blocks.
ntdll: Introduce a new BLOCK_FLAG_SPLIT heap block flag.
ntdll: Introduce a new subheap thread affinity field.
ntdll: Introduce a new heap block_init_used helper.
ntdll: Introduce a new heap free_list_init helper.
ntdll: Count allocations and automatically enable LFH.
ntdll: Implement HeapCompatibilityInformation.
https://gitlab.winehq.org/wine/wine/-/merge_requests/1628