当前位置:网站首页>[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
边栏推荐
猜你喜欢

How to seamlessly transition from traditional microservice framework to service grid ASM
![克隆無向圖[bfs訪問每條邊而不止節點]](/img/34/2a1b737b6095293f868ec6aec0ceeb.png)
克隆無向圖[bfs訪問每條邊而不止節點]

SOFARegistry 源码|数据同步模块解析
![[advanced C language] string and memory function (II)](/img/1a/14ff6a078419e407845d60485be60e.png)
[advanced C language] string and memory function (II)

vsftp 与 TFTP 与 samba 与 nfs 复习
![Majority element ii[molar voting method for finding modes]](/img/8f/5925f97c0f5f8c50c19a9ef6d7723c.png)
Majority element ii[molar voting method for finding modes]

云呐|固定资产系统管理的优势,固定资产管理系统有何特点

HDCP Paring

Can't recognize the original appearance
![[advanced C language] string and memory function (I)](/img/fa/5531253940d99f2646cb6964992e7c.png)
[advanced C language] string and memory function (I)
随机推荐
leetcode 416. Partition equal subset sum partition equal subset sum (medium)
间歇采样转发干扰
云呐|固定资产系统管理的优势,固定资产管理系统有何特点
How long will it take to open a mobile account? In addition, is it safe to open a mobile account?
01 backpack problem
剑指 Offer II 035. 最小时间差
Mysql Duplicate entry ‘xxx‘ for key ‘xxx‘
MySQL基礎2
请指教在线开户是什么意思?另外想问,现在在线开户安全么?
单位固定资产怎么管理,行政单位的固定资产应该怎么管理
Serpentine matrix (array simulates direction, D represents turning)
Label Troubleshooting: unable to open the marked image
Solr basic operation 8
Copy linked list with random pointer [space for time --hash record]
[advanced C language] string and memory function (I)
Connection query of SQL Server database
modbus-tcp-rtu协议图表
股票网上开户及开户流程怎样?还有,在线开户安全么?
Solr基础操作7
C MDI open subform to remove automatically generated menu bar