开发者

gettype() leaking memory

开发者 https://www.devze.com 2023-02-04 00:45 出处:网络
I\'m using the twitter-async library to do some oauth calls to twitter but ultimately, a lot of memory is being used up. I tried running the xdebug execution trace and this is where I feel t开发者_JAV

I'm using the twitter-async library to do some oauth calls to twitter but ultimately, a lot of memory is being used up. I tried running the xdebug execution trace and this is where I feel t开发者_JAVA百科he memory is getting leaked.

json_decode() is using 47077232 bytes. Okay. This is fine.

But gettype() ? Why should this too be using similar amount of memory?

How could this be prevented?

The script runs in a loop and the memory usage keeps going up. I'm using gc_collect_cycles() at number of places and it is showing improvement. But this one, I can't understand why should this happen.

  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


From the documentation:

Never use gettype() to test for a certain type, since the returned string may be subject to change in a future version. In addition, it is slow too, as it involves string comparison.

Instead, use the is_* functions.

e.g. use is_array, is_string etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消