0
많은 Magic 메서드 __call을 사용하여 스크립트를 작성했습니다. 스크립트의 반복 횟수는 15 000이며 개체가 더 큽니다. 매 반복 후에 메모리가 커집니다. 나는 unset 또는 $ val = null; 그러나 기억은 계속해서 커집니다.Php5.3 마법 방법 __call 및 메모리
어떻게해야합니까?
Exemple :
$data = null;
foreach ($field['method']['actions'] as $action) {
// si l'action ne concerne pas le name space principal
if (!array_key_exists('get', $action)) {
continue;
}
if (array_key_exists('begin', $action)) {
$data .= $action['begin'];
}
if (array_key_exists('action', $action)) {
$obj = $notice->__call('get' . ucfirst($action['action']));
$notice->clear();
if (is_object($obj)) {
$rsl = $obj->__call('get' . ucfirst($action['get']));
$obj->clear();
echo "\n" . 'get' . ucfirst($action['get']) . ' : ' . number_format(memory_get_usage());
$data .= $rsl;
unset($rsl);
} else {
$data .='';
}
$obj = null;
} else {
$data .= $notice->__call('get' . ucfirst($action['get']));
$notice->clear();
echo "\n" . 'get' . ucfirst($action['get']) . ' : ' . number_format(memory_get_usage());
}
if (array_key_exists('end', $action)) {
$data .= $action['end'];
}
}
//--
class Notice{
//--
protected $instanceObj = null;
public function __call($name, $arguments = null) {
$this->instanceObj = $this->$name($arguments);
return $this->instanceObj;
}
public function clear(){
$this->instanceObj = null;
}
//--
}
로그 파일의 exemple : 당신은 눈썹을 중지 메모리를 절대 볼 수 없습니다
getField : 24,446,752
getField : 24,447,352
getField : 24,447,720
getField : 24,448,096
getField : 24,483,320
getField : 24,483,336
getField : 24,483,728
...
getField : 25,267,936
...
getField : 35,596,712
...
.
PHP에서 메모리 누수가 발견되었다고 생각하는 경우 버그 리포트를 게시하고 "고맙지 만 버그가 아닙니다"라는 대답을 얻을 수 있습니다. 이것이 PHP 버그와 함께하는 일반적인 방법입니다. 그렇지 않으면, 만약 당신이 여전히 메모리 누출을 전시하고 여기에 게시하는 최소한의 예제를 만들 수 있다면, 우리는 그 밖의 다른 것이 있는지 살펴볼 것입니다. – lanzz
제 질문은 완료되었습니다 – vinzcoco
코드는 문제를 재현하기에 충분하지 않습니다. 당신은'Notice :: __ call()'을 마법 메서드 _at all_ (당신이 명시 적으로 호출 했으므로 아무런 마술도 일어나지 않음)로 호출하지 않고,'__call()'메서드 내에서 다른'Notice' 메서드를 호출하고 있습니다 이는 여러분의 예제에서는 정의되지 않았으며 코드를 실행하기위한 입력 데이터 ('$ field [ 'method'] [ 'actions']'배열)가 없습니다. – lanzz