There are a number of possible causes. Cache isn't really on of them. The two primary causes are:
- A large collection being read into memory at once.
- A nested infinite loop that creates one or more new instances of the same entity.
The first should immediately spark a lightbulb over your head :-) and the fix is to either use the paging functionality for collections, which fetches a large results in chunks. Or one can use the collection iterator.
But it's sometimes less obvious, for example when you've provided a "view all products in this category" page and over time or through an import error this category has become loaded with hundreds or even thousands of products.
The second is a common mistake in many extensions that are part of the totals collection process in the cart.
In order to do their work they need some information from the current quote and then request it from the cart. This is incorrect when a flag has been set in the quote that signals Magento that prices may have changed out of band.
The handling of this recalculation is done in the cart
_afterLoad, which means the cart has not finished loading. You guessed it, requesting the information from the cart at that point will once again start the loading cycle and creates a new cart instance and any objects that methods create during their collectTotals process.
The only time I've seen cache be a problem in relation to memory is when saving the cache fails and the memory involved creating the information to be cached isn't freed, leading to starvation of memory over time. Still not hitting this error.
This fits the pattern of cache: it should eliminate operations to construct certain objects and just hand you the result. As a rule of thumb, constructing something requires other somethings, and will therefore use more resources including memory.
Here's the case when this happens on checking account view page:
- When a customer logs in, her old abandoned carts are merged with her current cart.
- If trigger_recollect is present on one of the old carts (
SELECT s.created_at, s.updated_at, s.customer_email FROM sales_flat_quote s LEFT JOIN customer_entity e ON s.customer_id=e.entity_id WHERE s.trigger_recollect=1) this initiates the collect totals.
If you have MultiSafePay 1.x (aka Mage/MSP) installed and use catalog rules, you can be sure you have the problem.