I tried to work with image/gif, which caused too much memory usage for my project and it wouldn’t be freed, and finally I found out that it was a problem with this library?
You can take a look at the simple code below, he occupies too much physical memory, and most of it is sharing memory, and even manual gc can’t release it, I use a tool for prometheus to show the actual physical memory, which is very abnormal.
This res. The gif is only 20MB, it’s just irrelevant, according to my tests, this problem doesn’t occur on my macos, the object memory is freed, and on my ubuntu, the object memory is also freed, but the shared memory is not freed (in macos this part is also freed), which makes me wonder, obviously, the example code is very simple, the object is also gc, but the actual physical memory, on ubuntu and macos does not behave the same.
This will happen whether it is main or init, at first I modified the source code to read the picture frame in streaming, and then I found that as I continued to read the picture frame, the shared memory would gradually become larger, and the gif library was just read once in a for loop, and the result was the same.
Interesting that you mention MacOS vs. Linux difference. It may actually be “working as designed”. I found this StackOverflow answer that may be relevant to your case.
I thought of this because of how Apple advertises that 8GB is enough. They might just be throwing some of the POSIX standard out the window for efficiency’s sake.
Interesting, but I still don’t know why this shared memory gets bigger and bigger as I parse more image frames, and when I start the second process and repeat it, the shared memory also starts from scratch and gradually grows larger, which looks like the process has monopolized the shared memory and becomes a proprietary memory that cannot be freed.