Ok, so I am looking for a way to unset ALL variables generated by a page but NOT global variables or Sessions.
I found this in another SO question:
$list_of_vars = array_diff(get_defined_vars(), $GLOBALS); // Was just get_defined_vars() before Marc B corrected me in his post.
foreach($list_of_vars as $var){
unset($var);
}
The thing is that in the comments it was said that this unsets() ALL as in ALL variables the include globals and Sessions. I need a way to reset all variables that are NOT global and NOT Sessions
I am doing this for optimizing RAM. If this doesn’t help then, is there any other way of optimizing RAM?
This is definitely not the way to go to optimize your script’s RAM usage.
You want to identify the problem areas of your script, and work on those.
It’s hard to give any hints without knowing what your script does. Here are some pointers to discussion on SO (partly very high-level and/or Framework-specific, but they still contain valuable info):
How to optimize the php process memory usage? (if you have the option to install new software to aid your PHP processes)
Optimize my performance
Simple but heavy application consuming a lot of resources. How to Optimize? (about mySQL usage optimization really)