Recursive Reference of PHP Objects causes memory leakage analysis and php recursion. Recursive Reference of PHP Objects causes memory leakage analysis. php recursion usually results in memory leakage if PHP Objects have recursive references. This Bug has existed in PHP for a long time. Recursive Reference of PHP Objects causes memory leakage analysis and php recursion.
Generally, if PHP Objects have recursive references, memory leakage may occur. This Bug has existed in PHP for a long time. let's reproduce it first. the sample code is as follows:
<?phpclass Foo { function __construct() { $this->bar = new Bar($this); }}class Bar { function __construct($foo) { $this->foo = $foo; }}for ($i = 0; $i < 100; $i++) { $obj = new Foo(); unset($obj); echo memory_get_usage(), "/n";}?>
Run the above code and you will find that the memory usage should not change, but it is actually increasing, and the unset does not take effect completely.
Most of the current development is based on the framework. if there is a complex object relationship in the application, you may encounter such a problem. let's take a look at the appropriate measures:
<?phpclass Foo { function __construct() { $this->bar = new Bar($this); } function __destruct() { unset($this->bar); }}class Bar { function __construct($foo) { $this->foo = $foo; }}for ($i = 0; $i < 100; $i++) { $obj = new Foo(); $obj->__destruct(); unset($obj); echo memory_get_usage(), "/n";}?>
The solution is a bit ugly, but it is finally a battle. FortunatelyThis Bug has been fixed in the CVS code of PHP5.3..
In this regard, it is necessary to pay attention to the PHP program design! I believe this article has some reference value for everyone's PHP program design.
PHP recursion
Function demo has two inevitable output statements: the first and the last!
Function running process
1. output num
2. determine if num is greater than 0 and whether to call the function.
3. output num
When num is greater than 0, every time you call a function, you can only execute step 1. then, wait for the second step to call its own returned results and continue execution. therefore, after each call ends and returns, the num is output again, that is, the value following the result is output in reverse order!
Php recursive call
Well, just give me a few comments.
When writing SQL statements, it is best to write mysql functions in uppercase. in this case, SQL statements can be clearly described.
For example, $ SQL = "SELECT * FROM 'user' WHERE 'id' = '$ ID '";
In addition, table names and field names are all contained by vertices next to '1' (points under the English input method) and variables copied to the field are enclosed by 'single quotes for both string and numeric types.
But it's very good .....
In general, if PHP Objects have recursive references, memory leakage may occur. This Bug has existed in PHP for a long time ,...