getType()泄漏内存
-
11-10-2019 - |
题
我正在使用 Twitter-Async库 要对Twitter进行一些呼叫,但最终,正在使用很多内存。我尝试运行Xdebug执行跟踪,这是我觉得内存泄漏的地方。
json_decode()
使用47077232字节。好的。这可以。
但 gettype()
?为什么这也应该使用类似的内存?
如何防止这呢?
脚本以循环运行,内存使用量不断上升。我在用着 gc_collect_cycles()
在地点数量,它显示出改进。但是这是,我不明白为什么会发生这种情况。
724.1772 47077232 +2118720 -> json_decode() /var/www/html/includes/classes/twitter/EpiTwitter.php:230
724.1926 49157104 +2079872 -> gettype() /var/www/html/includes/classes/twitter/EpiTwitter.php:232
724.1927 49157104 +0 -> property_exists() /var/www/html/includes/classes/twitter/EpiTwitter.php:240
724.1927 49153520 -3584 -> EpiTwitterJson->__destruct() /var/www/html/includes/classes/twitter/EpiTwitter.php:0
724.1949 46714808 -2438712 -> in_array() /var/www/html/cron.php:156
解决方案
来自 文档:
切勿使用getType()测试某种类型,因为返回的字符串可能会在将来的版本中更改。另外,它也很慢,因为它涉及字符串比较。
而是使用IS_*函数。
例如使用 is_array
, is_string
等等
不隶属于 StackOverflow