oxipng icon indicating copy to clipboard operation
oxipng copied to clipboard

memory allocation of x bytes failed

Open guilhermesimoes opened this issue 9 months ago • 5 comments
trafficstars

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.

guilhermesimoes avatar Feb 20 '25 15:02 guilhermesimoes

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.

andrews05 avatar Feb 20 '25 18:02 andrews05

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!

guilhermesimoes avatar Feb 20 '25 22:02 guilhermesimoes

@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?

TPS avatar Feb 21 '25 13:02 TPS

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).

andrews05 avatar Feb 23 '25 04:02 andrews05

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?

TPS avatar Feb 23 '25 04:02 TPS

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.

andrews05 avatar Apr 26 '25 00:04 andrews05