I just ported some code from C/C++ to Go, it is a microservice. It works well, even faster than in C/C++. But I have a problem with memory.
When my program starts it will allocate about 4.5GB RAM and will fill it with data from disc also processing data while loading, then it will run for days(hopefully months) serving the requests from RAM. Unfortunately after the processing and placement of data in RAM is finished, extra 3.5 GB of RAM remains allocated by Go. I do not do any deallocations, only allocations, I do not think my program really uses 8 GB at any point, so I think Go just acquires extra RAM because it "feels" I might need more soon, but I will not.
I read that Go does not allow any functionality to deallocate unused RAM to return it to system. I want to run more services on the same machine, saving as much of RAM as possible, so wasting almost as much as I really use feels wrong.
So how do I keep the memory footprint compact avoiding those empty 3.5 GB being allocated by Go?