I’m using twitter-async library to interact with twitter api. However, the memory limit keeps increasing even if I use gc_enable() and gc_collect_cycles() after various unset()s
Before using garbage collector, memory usage was too much. It has certainly decreased a lot. But not satisfactorily.
I’m running a for loop that checks for new requests in database and processes them.
Suppose, a request is processed, generating around 98 MB (this is fine — considering the amount of data I’m fetching from twitter) of memory, and there are no more requests to be processed, then this 98 MB of data will stay forever until php reaches the 260MB memory limit I have setup. I’ve already setup monit that restarts the script if it crashes due to memory limit.
After investigating a bit, I found that the library saves data about failed calls,etc in some variables. Is there a way with which I can destroy the entire class that will unset all the memory-hungry variables and save the memory? I’m currently just unset()ing the variable for the class.
$twitterObj = new EpiTwitter();
// Do all the stuff ..
unset($twitterObj);
But there still isn’t any change in memory usage.
Help!
This can happen if any other object keeps reference to either
$twitterObjitself or some big data inside it. You could define a destructor__destruct()for the class to see if the object is actually destroyed (it is called on actual destruction).I would also recommend using a profiler – such as xhprof or xdebug or Zend products – to see memory usage and find where the memory is wasted.