oxipng
oxipng copied to clipboard
memory allocation of x bytes failed
On Windows 11 I have a folder of about 20 images, each image with a size between 10 to 20 MB.
Running this command inside the folder:
oxipng.exe -o max --strip safe --alpha *.png
results in the following error:
memory allocation of 8597908 bytes failed
If I run oxipng on each image individually it works.
It appears that when using a wildcard / glob oxipng tries to load all the images at once and so it runs out of memory.
Hi @guilhermesimoes Sorry to hear this Is happening. How much memory and how many cpu cores do you have?
You should be able to work around the issue by capping the number of threads that oxipng uses. E.g. try using -t4 or similar.
I have 8 cores. Running systeminfo |find "Available Physical Memory" (from https://superuser.com/a/315203) now I get back the value 4,928 MB. But maybe at the time I had less memory available. I will use -t4 next time I need to optimize multiple images. Thank you!
@andrews05 IIUC, w/ the command-line as given, this shouldn't happen, right? I thought OxiPNG should fall back to work w/in system available resources?
Oxipng doesn't currently have any constraints on memory usage (see #411). But more threads = more memory, so you can still exert some control over memory by capping the threads (which defaults to the number of cpu cores you have).
But more threads = more memory, so you can still exert some control over memory by capping the threads (which defaults to the number of cpu cores you have).
Perhaps it'd be worth automatically lowering that thread # (w/ a console note @ appropriate log level) if OxiPNG calculates it won't have enough resources to maintain that default?
Closing this for now as we've made some improvements in v9.1.5 to reduce memory usage. Beyond that it's up to the user to employ flags like --threads or --sequential when necessary.