PHP essentially has no memory leak because it works with memory managed by the language through a garbage collector based on reference count with additional collection of cycles , then the leak can only occur if you have a bug on it or the cycle sink is turned off. See zend.enable-gc
, gc_enable()
and gc_collect_cycles()
.
Creating cycles is not easy. If you are doing this you have a great chance of being too confused.
Moreover, under normal PHP usage conditions it is not even to have memory retained for exaggerated time since scripts run for very little time, so in practice if you did not even have a garbage collector you would do little difference since soon after the memory will be released integrally.
If Doctrine's does something that is causing problems, report it to creators or use something that does not have such a serious problem.
If you are holding too much memory you have to analyze the code, there is a magic formula that says looks in such a place and you will see the leak. Any potential allocation may be holding back memory. But retention is not leakage.
You may be holding information too long because you have left some resource that uses unmanaged memory opened for too long. Every time you use an external resource such as a file, database, network, or other type of service you need to close it. But even this is not to cause a problem because at the moment the variable holding this open resource goes out of scope it is released automatically either by the reference count or by the cycle sink. And if all this fails it will be closed at the end of script .
Maybe you're just carrying too much stuff in your memory. You have to analyze the code and go around where it makes large loads of memory and see if you can load less or load slowly.
Read more about GC .