简体   繁体   中英

Unset all variables? (Not $_SESSION[''] or globals)

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):

如果您希望修复脚本中的大量RAM使用量,则最好通过概要分析来查看脚本的确切作用!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM