Improve GC with external library that may use large memory
GC cares memory allocated by only Ruby. GC doesn't care memory allocated by external library. GC isn't run frequently when external library allocates large memory but Ruby allocates only small memory. In the case, process uses large memory. e.g.: Programs that handle large images may use large memory even when most images are garbage.
How about improving GC to care memory allocated by external library? It means that GC is run when external library allocates large memory.
I created a gem to show the concept: https://github.com/kou/gc-trigger
The gem provides an API that accepts diff of memory usage of external library. Bindings of external library notify diff of memory usage of external library. GC is run when total memory usage of external library overs threshold. Then memory of external library associated with garbage Ruby objects is freed.
Yellow line is memory usage without the concept and blue line is memory usage with the concept:
Memory usage is increased without the concept but stable with the concept.
See also: https://github.com/kou/gc-trigger#effect
V8 has an API that is similar to the concept: