0

UPDATE I noticed that with a particular require_once('myobject.php') that the memory increase showed up. This require_once() was run conditionally. When I moved the require_once()statement out of the if statement so it loads all the time, the memory increase went away. Doesn't make sense to me, but the issue is solved. I'm not sure this is actually an "answer" so I will leave it unanswered.

I have memory_get_usage() in the footer of my page and with each refresh of the page, I watch it increase by about 100k each time. My page load creates many objects and destroys them when done . My parent objects each have __destruct() which uses unset() with all child objects. Child objects with a reference back to the parent, have __destruct() to unset() these references.

Inserting memory_get_usage() before and after processing different parts of my page only tells me how much of the total usage was added due to that part of the script. How do I go about determining what memory is lost and not recycled for garbage collection after the page finishes loading?

I have one global $_SESSION var containing objects storing user info, but have verified using strlen(serialize($object)) that this object is not growing in size.

I presume that what I am seeing is a memory leak and that php garbage collection should be in effect after the script ends. Any ideas how to debug this?

4

1 回答 1

2

如果我错了,有人可以纠正我,但如果你有一个标准的 Apache 和 PHP 设置,PHP 进程在请求完成后被销毁,所以它不会在请求之间使用内存。

所以unset(),__destruct()等无关紧要(跨请求)。当 PHP 进程结束时,所有内存都被回收。

但很可能没有内存泄漏,但可能某些会话文件的大小增加了,因此下次加载时它会更大。

注意:这对于 php-fpm 可能会有所不同,我不确定。

于 2013-10-31T21:49:46.020 回答