How to force clean memory on PHP? Version PHP: 5.5
My symfony2 command:
namespace NNNN\NNNN\Command;
use NNNN\NNNN\Model\Newsletter;
use NNNN\NNNN\Model\NewsletterQuery;
use NNNN\NNNN\Model\UsersNewslettersQuery;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class UsersNewslettersFixCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('users:newsletters:fix')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$counter = 0;
$users = UsersNewslettersQuery::create()
->setFormatter(\ModelCriteria::FORMAT_ON_DEMAND)
->find();
foreach ($users as $user) {
if ($city = $user->getCity()) {
$countryId = $city->getCountryId();
} elseif ($location = $user->getLocation()) {
$countryId = $location->getCountryId();
} elseif ($region = $user->getRegion()) {
$countryId = $region->getCountryId();
}
if (isset($countryId)) {
$user->setCountryId($countryId);
$user->save();
}
++$counter;
}
$output->writeln('Handled '.count($counter).' users');
}
}
How to force clean memory after some iterattion? gc_collect_cycles after ++$counter does not effect on memory using.
get_memory_usage output: