Open hw-dwalter opened 9 years ago
Hello @hw-dwalter
Thanks for your request. Yes, this is a wider problem if you create a long life script because more objects in original extension use store pointer as boost::shared_ptr and zend engine can't free them. But you're right if we create custom destructor on extension side it could be good decision. I'll try to do that as soon as possible.
Any progress on this bug? I'm getting bit by it hard. Even with the workaround I'm still seeing a 1KB/query leak. It doesn't sound like much, but my script runs for hours with millions of queries. I end up leaking 4GB, at which point the script gets killed.
Problem
Instances of the
CqlQuery
class in PHP never gets deleted. While looking deeper at this bug, arouse suspicion this may be a bug in all classes exposed to PHP.In my case this quickly exceeds all of the available memory. This PHP code shows up the problem:
In such a case this c++ code is evaluated in each round of the loop
Proof
This new object of type
cql::cql_query_t
never gets deleted! I also did a valgrind memory check to find this problem. Here you can see the corresponding valgrind output:Proposal for solution
I am not an expert in PHP extension development, but it seems to me that there is no dtor defined in this calls:
The
zend_objects_store_put
function is defined as this:My suggestion is to add appropriate dtor functions in all
zend_objects_store_put
calls. As far as I can see, this problem exists for all classes!Workaround in PHP
If you avoid building new
CqlQuery
objects each step in the loop, the memory leak does not kills your memory too quick. Rearrange the PHP code like this works around this bug: