当前位置:网站首页>【PHP】PHP变量内存释放
【PHP】PHP变量内存释放
2022-06-30 00:24:00 【weixin_43224306】
通过 PHP memory_get_usage() 函数获取当前进程占用的物理内存,比较得出:
1、unset() 函数可以释放内存
2、函数内部的局部变量在函数执行完成会自动释放
看下面的代码:
<?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
结果:
2 --355056
6-- 379664
10-- 355088
14 --355088
第一列是行号
结论
在明显的地方可以使用 unset() 函数显示的回收内存,在功能复杂的场景下可以采用函数形式回收内存
边栏推荐
- Do mysqlcdc data not support windowing functions like row_ Number, lead
- SOFARegistry 源码|数据同步模块解析
- HDCP Paring
- TP5 query and and or condition nesting
- This PMP Exam (June 25), some people are happy and others are worried. That's why
- Solr基础操作14
- 项目一:部署 LAMP ecshop电商平台
- [advanced C language] user defined type
- Several simple queries of SQL Server database
- vim插件管理器vim-plug安装方法
猜你喜欢

微信支付 APP端 第三弹 申请退款

QT learning 02 GUI program example analysis

Cloud native enthusiast weekly: cool collection of grafana monitoring panels

剑指 Offer II 035. 最小时间差

蛇形矩阵(数组模拟方向, d代表转弯)

Vulnhub target -moriartycorp

There is no web-based development for the reward platform. Which is suitable for native development or mixed development?

Sword finger offer II 035 Minimum time difference

01背包问题

HDCP Paring
随机推荐
QT learning 06 widgets and window types
MySQL基础3
项目一:部署 LAMP ecshop电商平台
JS的初步语法
微信支付 APP端 第三弹 申请退款
vim插件管理器vim-plug安装方法
[advanced C language] user defined type
视频ToneMapping(HDR转SDR)中的颜色空间转换问题(BT2020转BT709,YCbCr、YUV和RGB)
中小企业签署ERP合同时,需要注意这几点
Solr basic operations 14
间歇采样转发干扰
Events in JS
学位论文的引用
DOM 知识点总结
DataGridView上移 下移行
Rotating colored clover
云呐|固定资产系统管理的优势,固定资产管理系统有何特点
MySQL高级篇2
Mysql:sql overview and database system introduction | dark horse programmer
Solr basic operations 7