1

There are many questions already asked about this error, but I could not find a solution for my situation, so I created a new one where I hope to get answers to two very specific questions:

1. Where from does the number 2097152 come?

In my php.ini I have memory_limit set to 256M, in my wp-config.php I have WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT set to 256M, so I would expect to get errors stating that 268435456 bytes were allocated and exceeded, where from 2097152 comes?

2097152 = 2048K = 2M, I looked through all the files in Apache, PHP and WordPress folders and could not find any of these values used, please help.

2. Why is amount that was tried to allocate (4096) is less than allocated (2097152)?

Could someone please explain, what am I missing here?

Valdas
  • 368
  • 4
  • 14

1 Answers1

-1

You may be using too much memory for your PHP application. Possible cause could be infinite loops, too much data loaded to a variable/array(may be coming from the database) etc. You should not rely on increasing the memory size but rather find what's causing the problem and solve it there.

Use

error_log("Memory Usage: " . (memory_get_usage()/1048576) . " MB");

and place it on specific locations on your code where you suspect that there's a memory leak or seems that causes the problem.

rai
  • 449
  • 3
  • 10
  • I have some suspicions that plugins widged might be the cause, but I am not sure where to put this, for example I tried in [class-wc-widget-products.php](https://github.com/woocommerce/woocommerce/blob/master/includes/widgets/class-wc-widget-products.php#L168) file on lines 168 and 187, restarted the Apache, but nothing appeared in errors log. – Valdas Oct 20 '16 at 08:36
  • 1
    It's trial and error basically. If you want, you can put it at the start and end of each of your methods, modifying the label to identify on what part of the code it is executing. You'll notice that at some point it's eating up memory, and if it's not releasing it after the method has been executed. From there you may find the culprit. – rai Oct 20 '16 at 10:22
  • 1
    instead of using a label, add something like `__FUNCTION__` or `__FILE__` – RST Oct 20 '16 at 11:10
  • Please share more details. How does logging the used memory resolve the problem? – Nico Haase Mar 04 '22 at 09:08