I have read for years about ways to conserve memory when writing php scripts. But what type of scripts should I really concern myself with. What codes/scripts/call eat the most memory?
Edit
This is a question, please do not answer it with a question
Edit
What about this. Does something like this eat memory? It needs to be done but should it be freed some how?
$manufacture = htmlspecialchars($_REQUEST["manufacture"]);
$manufacture = preg_replace("/[^0-9]/","", $manufacture);
$SQL = "SELECT * FROM STORE_MANUFACTURERS WHERE manufacturers_id = '$manufacture'";
$result = mysql_query( $SQL );
while( $row = mysql_fetch_array( $result ) ) {
$manufacturers_name = $row['manufacturers_name'];
}
There are so many things to think when you go for a 100% perfect out look regarding memory leak. What I do is to follow the coding standards and patterns . and if I get into memory leak trouble even after that I should figure that out with profiling Tools like XDebug or Kcachegrind.
Things Like Exception safety should be well maintained
You can use tools like
memory_get_peak_usage(),memory_get_usage()to spot the culprit. You may check out this post regarding Memory Manager.Scripting Languages like PHP uses automatic garbage collection e.g. you don’t have to dealloc by yourself. the garbage collector does it for you (using reference counting). but if you want to do it by yourself you may use
unset(). but some scenarios has been reported when even unset doesn’t do it for you. Some Bugs have been reported regarding this too.bug#33945bug#33487reference countingwill run into problem when botha:Aandb:Bhave a circular reference so you need the one instance to take theownershipand destruct the referred object to break the circle to face this issue.There are some issues with strtotime() memory leak
bug#47285The code you have posted in your edit shouldn’t have any concern of having memory leak. I’ll quote @GolezTrol in comments