目次
PHP的unset()函数的实际效果
PHP代码:
ホームページ php教程 php手册 PHP的unset()函数的实际效果

PHP的unset()函数的实际效果

Jun 13, 2016 am 11:16 AM
php unset 関数 共有 実際の 提案 効果

 

PHP的unset()函数的实际效果

强烈建议大家没事就分享这种技术文章

PHP变量对内存的开销与释放,unset()是否真的释放内存。转自:PHP的unset()函数的实际效果
测试代码如下: 复制PHP内容到剪贴板
PHP代码:
<font face="NSimsun"><span style="color: #007700">for ( </span><span style="color: #0000bb">$i </span><span style="color: #007700">= </span><span style="color: #0000bb">1</span><span style="color: #007700">; </span><span style="color: #0000bb">$i </span><span style="color: #007700"><span style="color: #0000bb">100</span><span style="color: #007700">; </span><span style="color: #0000bb">$i</span></span></font><font face="NSimsun"><span style="color: #007700">++ ) {<br>         </span><span style="color: #0000bb">$str </span><span style="color: #007700">= </span><span style="color: #0000bb">str_repeat</span><span style="color: #007700">(</span><span style="color: #dd0000">'01234567'</span><span style="color: #007700">, </span><span style="color: #0000bb">$i</span></font><font face="NSimsun"><span style="color: #007700">);<br>         </span><span style="color: #0000bb">$a </span><span style="color: #007700">= </span><span style="color: #0000bb">memory_get_usage</span></font><font face="NSimsun"><span style="color: #007700">();<br>         unset(</span><span style="color: #0000bb">$str</span></font><font face="NSimsun"><span style="color: #007700">);<br>         </span><span style="color: #0000bb">$b </span><span style="color: #007700">= </span><span style="color: #0000bb">memory_get_usage</span></font><font face="NSimsun"><span style="color: #007700">();<br>         echo </span><span style="color: #dd0000">"n<br>" &gt;</span><span style="color: #007700">.</span><span style="color: #0000bb">$i</span><span style="color: #007700">.</span><span style="color: #dd0000">': '</span><span style="color: #007700">.(</span><span style="color: #0000bb">$b </span><span style="color: #007700">- </span><span style="color: #0000bb">$a</span><span style="color: #007700">).</span><span style="color: #dd0000">' Bytes.'</span></font><font face="NSimsun"><span style="color: #007700">;<br> }</span></font>
  从结果看出:8 x 32 = 256 在256字节长的时候才真正有必要释放内存,有些人说,不如直接$str = null来的速度快。
下面是实际结果:
结果如下:
1: 0 Bytes.
2: 0 Bytes.
3: 0 Bytes.
4: 0 Bytes.
5: 0 Bytes.
6: 0 Bytes.
7: 0 Bytes.
8: 0 Bytes.
9: 0 Bytes.
10: 0 Bytes.
11: 0 Bytes.
12: 0 Bytes.
13: 0 Bytes.
14: 0 Bytes.
15: 0 Bytes.
16: 0 Bytes.
17: 0 Bytes.
18: 0 Bytes.
19: 0 Bytes.
20: 0 Bytes.
21: 0 Bytes.
22: 0 Bytes.
23: 0 Bytes.
24: 0 Bytes.
25: 0 Bytes.
26: 0 Bytes.
27: 0 Bytes.
28: 0 Bytes.
29: 0 Bytes.
30: 0 Bytes.
31: 0 Bytes.
32: -272 Bytes.
33: -280 Bytes.
34: -288 Bytes.
35: -296 Bytes.
36: -304 Bytes.
37: -312 Bytes.
38: -320 Bytes.
39: -328 Bytes.
40: -336 Bytes.
41: -344 Bytes.
42: -352 Bytes.
43: -360 Bytes.
44: -368 Bytes.
45: -376 Bytes.
46: -384 Bytes.
47: -392 Bytes.
48: -400 Bytes.
49: -408 Bytes.
50: -416 Bytes.
51: -424 Bytes.
52: -432 Bytes.
53: -440 Bytes.
54: -448 Bytes.
55: -456 Bytes.
56: -464 Bytes.
57: -472 Bytes.
58: -480 Bytes.
59: -488 Bytes.
60: -496 Bytes.
61: -504 Bytes.
62: -512 Bytes.
63: -520 Bytes.
64: -528 Bytes.
65: -536 Bytes.
66: -544 Bytes.
67: -552 Bytes.
68: -560 Bytes.
69: -568 Bytes.
70: -576 Bytes.
71: -584 Bytes.
72: -592 Bytes.
73: -600 Bytes.
74: -608 Bytes.
75: -616 Bytes.
76: -624 Bytes.
77: -632 Bytes.
78: -640 Bytes.
79: -648 Bytes.
80: -656 Bytes.
81: -664 Bytes.
82: -672 Bytes.
83: -680 Bytes.
84: -688 Bytes.
85: -696 Bytes.
86: -704 Bytes.
87: -712 Bytes.
88: -720 Bytes.
89: -728 Bytes.
90: -736 Bytes.
91: -744 Bytes.
92: -752 Bytes.
93: -760 Bytes.
94: -768 Bytes.
95: -776 Bytes.
96: -784 Bytes.
97: -792 Bytes.
98: -800 Bytes.
99: -808 Bytes.
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットな記事タグ

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

Ubuntu および Debian 用の PHP 8.4 インストールおよびアップグレード ガイド Ubuntu および Debian 用の PHP 8.4 インストールおよびアップグレード ガイド Dec 24, 2024 pm 04:42 PM

Ubuntu および Debian 用の PHP 8.4 インストールおよびアップグレード ガイド

CakePHP の日付と時刻 CakePHP の日付と時刻 Sep 10, 2024 pm 05:27 PM

CakePHP の日付と時刻

CakePHP プロジェクトの構成 CakePHP プロジェクトの構成 Sep 10, 2024 pm 05:25 PM

CakePHP プロジェクトの構成

CakePHP ファイルのアップロード CakePHP ファイルのアップロード Sep 10, 2024 pm 05:27 PM

CakePHP ファイルのアップロード

CakePHP ルーティング CakePHP ルーティング Sep 10, 2024 pm 05:25 PM

CakePHP ルーティング

CakePHP について話し合う CakePHP について話し合う Sep 10, 2024 pm 05:28 PM

CakePHP について話し合う

CakePHP クイックガイド CakePHP クイックガイド Sep 10, 2024 pm 05:27 PM

CakePHP クイックガイド

PHP 開発用に Visual Studio Code (VS Code) をセットアップする方法 PHP 開発用に Visual Studio Code (VS Code) をセットアップする方法 Dec 20, 2024 am 11:31 AM

PHP 開発用に Visual Studio Code (VS Code) をセットアップする方法

See all articles