I am getting "Fatal error: Allowed memory size of XXXX bytes exhausted...". I need to iterate through big amount of records, and execute a function to verify of the record fit the criteria which declare many class variables.
foreach ($results as $row)
{
  $location = Location::parseDatabaseRow($row);
  if ($location->contains($lat, $lon))
  {
    $found = true;
    $locations[] = $location;
    break;
  }
}
Implementation of the Location class:
public function contains($lat, $lon)
{ 
  $polygon =& new polygon();
  .... //Add points to polygons base on location polygons
  $vertex =& new vertex($lat, $lon);
  $isContain = $polygon->isInside($vertex); 
  $polygon->res(); //Reset all variable inside polygons
  $polygon = null; //Let Garbage Collector clear it whenever
  return ($isContain);
}
Shouldn't the $polygon be clear when contain() method is return? What can I do to reduce memory usage?
I am a Java developer, and started to learn PHP. Please help me understand on how to manage stack size and memory allocation and delocation. Thanks in advance.
 
    