Server memory management mechanism
The underlying principle of memory management after Server is started is the same as that of the ordinary php-cli program. For details, please refer to the Zend VM memory management article.
local variables (Recommended learning: SWOOLE Video Tutorial )
## After the event recovery function returns, all local objects and variables will be recovered. No need to unset. If the variable is a resource type, the corresponding resource will also be released by the bottom layer of PHP.function test() { $a = new Object; $b = fopen('/data/t.log', 'r+'); $c = new swoole_client(SWOOLE_SYNC); $d = new swoole_client(SWOOLE_SYNC); global $e; $e['client'] = $d; }
Global variables
In PHP, there are 3 types of global variables. Variables declared using the global keyword Class static variables and function static variables declared using the static keywordSuper global variables of PHP, including $_GET, $_POST , $GLOBALS, etc.Global variables and objects, class static variables, variables saved on the Server object will not be released. Programmers need to handle the destruction of these variables and objects themselves.class Test { static $array = array(); static $string = ''; } function onReceive($serv, $fd, $reactorId, $data) { Test::$array[] = $fd; Test::$string .= $data; }
The above is the detailed content of Will swoole memory become larger and larger?. For more information, please follow other related articles on the PHP Chinese website!