{"action":"opened","issue":{"url":"https://api.github.com/repos/swoole/swoole-src/issues/536","repository_url":"https://api.github.com/repos/swoole/swoole-src","labels_url":"https://api.github.com/repos/swoole/swoole-src/issues/536/labels{/name}","comments_url":"https://api.github.com/repos/swoole/swoole-src/issues/536/comments","events_url":"https://api.github.com/repos/swoole/swoole-src/issues/536/events","html_url":"https://github.com/swoole/swoole-src/issues/536","id":136015163,"number":536,"title":"onFinish回调的疑似内存泄漏","user":{"login":"szyhf","id":14870120,"avatar_url":"https://avatars.githubusercontent.com/u/14870120?v=3","gravatar_id":"","url":"https://api.github.com/users/szyhf","html_url":"https://github.com/szyhf","followers_url":"https://api.github.com/users/szyhf/followers","following_url":"https://api.github.com/users/szyhf/following{/other_user}","gists_url":"https://api.github.com/users/szyhf/gists{/gist_id}","starred_url":"https://api.github.com/users/szyhf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szyhf/subscriptions","organizations_url":"https://api.github.com/users/szyhf/orgs","repos_url":"https://api.github.com/users/szyhf/repos","events_url":"https://api.github.com/users/szyhf/events{/privacy}","received_events_url":"https://api.github.com/users/szyhf/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-24T10:14:30Z","updated_at":"2016-02-24T10:14:30Z","closed_at":null,"body":"你好：\r\n       在使用server的onFinish回调中发现了一个疑似的内存泄漏情况。\r\n\r\n### 环境：\r\n    lsb_release -a\r\n        LSB Version:\t:core-4.1-amd64:core-4.1-noarch\r\n        Distributor ID:\tCentOS\r\n        Description:\tCentOS Linux release 7.2.1511 (Core) \r\n        Release:\t7.2.1511\r\n        Codename:\tCore\r\n\r\n       php7.0.2\r\n       swoole1.8.1  默认编译无设置参数。\r\n\r\nswoole配置：\r\n```\r\nworker_num               => 2\r\nmax_conn                 => 65535\r\ntask_worker_num          => 4\r\ntask_ipc_mode            => 2\r\ntask_tmpdir              => /Runtimes/Temp\r\ndispatch_mode            => 2\r\nmessage_queue_key        => 856752448\r\nbacklog                  => 128\r\nlog_file                 => /Log/NewServer.log\r\nheartbeat_check_interval => 6\r\nheartbeat_idle_time      => 12\r\nopen_length_check        => 1\r\npackage_length_type      => L\r\npackage_max_length       => 10485760\r\nopen_tcp_nodelay         => 1\r\nbuffer_output_size       => 10485760\r\ndiscard_timeout_request  => 1\r\n```\r\n### OnReceive回调中\r\n```\r\n$data = (string)time();\r\n$Server->task('hello task');\r\n$Server->send($fd,$data);\r\n```\r\n### OnTask回调中\r\n```\r\necho $msg.PHP_EOL；\r\n$server->finish('finish');\r\n```\r\n### 其他：\r\n设置了100个客户端持续向服务发送心跳包（自己定义的协议，无特殊功能，仅触发Receive用）\r\n### 现象：\r\n只要在OnTask中调用了finish方法，哪怕在worker的OnFinish回调中什么都不做，在worker进程中调用memory_get_usage(true)和memory_get_peak_usage(true)这两个方法获得的内存量都会缓慢上升，关闭客户端以后停止上升，运行一段时间不会下降（未被回收），从nomon也能看到系统内存持续下降的现象。如果使用kill -10重载服务，则内存恢复正常，但如果继续触发OnFinish，则又会慢慢上升。\r\n从我目前观察的情况，上升的规律很诡异的是每次2M，就是刚启动的时候是2m，第一次上升就变成4m，再上升就是6、8、10。。。这样\r\n如果不调用onFinish方法，则内存保持稳定无明显变化。\r\n"}}