当前位置:网站首页>[PHP] PHP variable memory release
[PHP] PHP variable memory release
2022-06-30 00:25:00 【weixin_ forty-three million two hundred and twenty-four thousan】
adopt PHP memory_get_usage() Function to get the physical memory occupied by the current process , The comparison shows that :
1、unset() Function can free memory
2、 The local variables inside the function will be automatically released after the function is executed
Look at the code below :
<?php
echo __LINE__ . ' ' . memory_get_usage() . "\n"; // 36640
function a () {
$a = str_repeat("Hello", 4242);
echo __LINE__ . ' ' . memory_get_usage() . "\n"; // 36640
unset($a);
echo __LINE__ . ' ' . memory_get_usage() . "\n"; // 36640
}
a();
echo __LINE__ . ' ' . memory_get_usage() . "\n"; // 36640
#unset($a);
#echo memory_get_usage() . "\n"; // 36744
result :
2 --355056
6-- 379664
10-- 355088
14 --355088
The first column is the line number
Conclusion
It can be used in obvious places unset() Function to display the reclaimed memory , In scenarios with complex functions, memory can be reclaimed in the form of functions
边栏推荐
猜你喜欢

MySQL advanced 1

Mysql:sql overview and database system introduction | dark horse programmer

自动融合,驰骋海外丨跨境电商YescomUSA携手云扩实现一站式自动化服务

有流量,但没有销售?增加网站销量的 6 个步骤

简要的说一下:Fragment 间的通信方式?

01 backpack problem
![[rust weekly library] Tokei - a utility for statistics of code lines and other information](/img/6c/4569cc0edaa01e4605c9c256193c31.png)
[rust weekly library] Tokei - a utility for statistics of code lines and other information

Finding a job in 2022 is the "last lesson" for graduates

剑指 Offer II 037. 小行星碰撞

蛇形矩阵(数组模拟方向, d代表转弯)
随机推荐
[advanced C language] dynamic memory management
Solr basic operation 16
Majority element ii[molar voting method for finding modes]
HDCP Paring
Solr基础操作16
Solr basic operations 7
How long will it take to open a mobile account? In addition, is it safe to open a mobile account?
Copy linked list with random pointer [space for time --hash record]
How to seamlessly transition from traditional microservice framework to service grid ASM
This PMP Exam (June 25), some people are happy and others are worried. That's why
传统微服务框架如何无缝过渡到服务网格 ASM
Stream collectors usage
云呐|如何利用系统管理固定资产?如何进行固定资产管理?
Web APIs environment object - dark horse programmer
@ConfigurationProperties使用不当引发的bug
Activity invitation | the Apache Doris community essay and speech solicitation activity has begun!
单位固定资产怎么管理,行政单位的固定资产应该怎么管理
Introduction to reptiles: data capture of Betta barrage, with 11 introductory notes attached
leetcode 416. Partition equal subset sum partition equal subset sum (medium)
Solr basic operations 9