Memory errors can be tricky to track down, and are almost always system specific (that's a fancy way of saying "I don't have a specific solution for you, but here's some debugging tips).
Memory problems usually happen for one of two reasons.
Repeated loading of something in a loop without clearing memory from the previous loop
Loading something too large
Based on your error message
Allowed memory size of 536870912 bytes exhausted (tried to allocate 501481472 bytes).
It sounds like you have PHP's memory limit set to 536870912 bytes (512MB
), and PHP ran into a problem when it attempted to allocate 501481472
bytes. That is, in a single operation, PHP attempted to set aside around 478MB of memory to hold the image helper object you attempted to put in a variable. (resize
returns $this
, meaning a copy of the image helper)
$variable = $this->helper('catalog/image')->init($product, 'small_image')->resize(135)
My guess is your base images are huge files, and that one the objects used by the image helper had that image loaded in memory. When cast that object as a string (which for an image helper returns the images URL, see its __toString
method.
$variable = (string)$this->helper('catalog/image')->init($product, 'small_image')->resize(135)
PHP didn't need to keep a copy of this around.
That, however, is just a guess. I'd up the memory limit temporarily to 1024MB
to see if that clears up the problem. If it doesn't, that means you have a runaway loop loading too many things. If it does clear the problem up, takes steps to up PHP's memory limit only when this operation needs to run.
So I cannot find the code getImagesMedia
anywhere and in the media.phtml the following is used
$this->getGalleryImages()
But even though I am not sure what you are talking about I can give you a general answer as to the difference between the following calls.
$this->getSomething() or $this->getData('something')
These are calls to get values directly from the block object, there will either be a function that matches in the block or at some point there will be a call to setSomething
$this->getChildHtml('something') or $this->getChild('something')
Now these two will either return the html or the block itself from a child block defined via the layout xml as follows.
<block name="your_parent_block">
<block type="some/type" name="something" />
</block>
Best Answer
Those 2 lines are not identical.
After the first line
$temp
will be an instance ofMage_Catalog_Helper_Image
. This is because theresize
method returns the currend object.After the second line
$temp
will be a string.When casting an object to a string it's the same as calling
$object->__toString();
You can take a look at the
Mage_Catalog_Helper_Image::__toString()
methods. This is the one that actually creates the cached, resized image if it doesn't exist and returns the url of the image.About the memory usage, I cant say much. What are you doing with
$temp
after the lines above? Maybe you do something that reaches the memory limit.