21293 Posts in 5733 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 927 Views |
-
Memory Management Issue & __destruct

24 May 2011 at 1:58am
Hi,
I have a memory management issue - calling
$vd->customise($arrdata)->renderWith('MyTemplate');
over and over in a loop - and it is failing with memory limit. I've tried adding...
unset($vd);
unset($arrdata);but this frees a tiny amount of memory and my reading of the php doc page is that it is only freeing the object, not the memory allocated by the object. To free that it would expect me to call it's decontructor first... it's "__destruct" method... I searched the code and couldn't find one... so...
what is the best way to manage memory for this in silverstripe?
-
Re: Memory Management Issue & __destruct

25 May 2011 at 5:21pm
hi,
I think this can sometimes help.
$vars = get_object_vars($vd);
foreach($vars as $val){
if(isset($vd->$val)){
unset($vd->$val);
}
} -
Re: Memory Management Issue & __destruct

25 May 2011 at 9:34pm Last edited: 26 May 2011 12:20am
Massive help, thanks!
I've now got this batch process working, I've changed the code a bit and it means that now when the memory limit is reached php does is garbage collection and everything works out fine! (instead of previously where none of the memory was able to be collected!). Note this version uses recursion to free all of the objects in it's object graph.
function dounset($var) {
$type=gettype($var);
if ($type=='object') {
$vars = get_object_vars($var);
if (count($vars)) foreach($vars as $val) {
$this->dounset($val);
}
}
else {
unset($var);
}
} -
Re: Memory Management Issue & __destruct

27 May 2011 at 2:42am
Quick note - this only works on php 5.3.x as you need the zend.enable_gc in the php.ini
| 927 Views | ||
|
Page:
1
|
Go to Top |


