{"action":"created","comment":{"url":"https://api.github.com/repos/barryz/go-bpt/pulls/comments/229572626","pull_request_review_id":170102937,"id":229572626,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyOTU3MjYyNg==","diff_hunk":"@@ -0,0 +1,173 @@\n+> 译自[Memory Leaking Scenarios](https://go101.org/article/memory-leaking.html)。\n+\n+# Go内存泄露的场景\n+\n+当使用一门支持垃圾回收的编程语言进行编程时，一般情况下，我们都不需要关心内存泄露的问题，因为语言的运行时将会定期收集无用的内存。然而，我们仍然需要注意一些可能会导致各类内存泄露的特殊场景。本文接下来的部分将会列举到这些场景。\n+\n+## 由子字符串引起的内存泄露\n+\n+Go规范没有指定子字符串表达式中涉及的结果字符串和基本字符串是否应该共享相同的底层[内存块](https://go101.org/article/memory-block.html)来管理这两个字符串的[底层字节序列](https://go101.org/article/string.html)。标准的Go编译器和运行时只是让它们共享了相同的底层内存块。这是一个很好的设计，从CPU和内存的开销方面来看。但是这样在有些情况下可能会导致内存泄露。\n+\n+例如，当下面例子中的`f`函数调用之后，将会有1M字节左右的内存泄露，知道包级别变量`s0`在其他的地方被修改为止。","path":"Memory-Related/Go_memory_leaking_scenarios.md","position":11,"original_position":11,"commit_id":"e6d87e79d1ffe11fbc8c3935930fc2869f98f584","original_commit_id":"e6d87e79d1ffe11fbc8c3935930fc2869f98f584","user":{"login":"barryz","id":16658738,"node_id":"MDQ6VXNlcjE2NjU4NzM4","avatar_url":"https://avatars0.githubusercontent.com/u/16658738?v=4","gravatar_id":"","url":"https://api.github.com/users/barryz","html_url":"https://github.com/barryz","followers_url":"https://api.github.com/users/barryz/followers","following_url":"https://api.github.com/users/barryz/following{/other_user}","gists_url":"https://api.github.com/users/barryz/gists{/gist_id}","starred_url":"https://api.github.com/users/barryz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/barryz/subscriptions","organizations_url":"https://api.github.com/users/barryz/orgs","repos_url":"https://api.github.com/users/barryz/repos","events_url":"https://api.github.com/users/barryz/events{/privacy}","received_events_url":"https://api.github.com/users/barryz/received_events","type":"User","site_admin":false},"body":"知道 -> 直到","created_at":"2018-10-31T06:05:16Z","updated_at":"2018-10-31T06:05:16Z","html_url":"https://github.com/barryz/go-bpt/pull/9#discussion_r229572626","pull_request_url":"https://api.github.com/repos/barryz/go-bpt/pulls/9","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/barryz/go-bpt/pulls/comments/229572626"},"html":{"href":"https://github.com/barryz/go-bpt/pull/9#discussion_r229572626"},"pull_request":{"href":"https://api.github.com/repos/barryz/go-bpt/pulls/9"}}},"pull_request":{"url":"https://api.github.com/repos/barryz/go-bpt/pulls/9","id":227168839,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI3MTY4ODM5","html_url":"https://github.com/barryz/go-bpt/pull/9","diff_url":"https://github.com/barryz/go-bpt/pull/9.diff","patch_url":"https://github.com/barryz/go-bpt/pull/9.patch","issue_url":"https://api.github.com/repos/barryz/go-bpt/issues/9","number":9,"state":"open","locked":false,"title":"go memory leaking scenarios doc done","user":{"login":"barryz","id":16658738,"node_id":"MDQ6VXNlcjE2NjU4NzM4","avatar_url":"https://avatars0.githubusercontent.com/u/16658738?v=4","gravatar_id":"","url":"https://api.github.com/users/barryz","html_url":"https://github.com/barryz","followers_url":"https://api.github.com/users/barryz/followers","following_url":"https://api.github.com/users/barryz/following{/other_user}","gists_url":"https://api.github.com/users/barryz/gists{/gist_id}","starred_url":"https://api.github.com/users/barryz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/barryz/subscriptions","organizations_url":"https://api.github.com/users/barryz/orgs","repos_url":"https://api.github.com/users/barryz/repos","events_url":"https://api.github.com/users/barryz/events{/privacy}","received_events_url":"https://api.github.com/users/barryz/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-10-31T06:02:37Z","updated_at":"2018-10-31T06:05:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b122b026f6739ec373b4efd69096f298f920fc20","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/barryz/go-bpt/pulls/9/commits","review_comments_url":"https://api.github.com/repos/barryz/go-bpt/pulls/9/comments","review_comment_url":"https://api.github.com/repos/barryz/go-bpt/pulls/comments{/number}","comments_url":"https://api.github.com/repos/barryz/go-bpt/issues/9/comments","statuses_url":"https://api.github.com/repos/barryz/go-bpt/statuses/e6d87e79d1ffe11fbc8c3935930fc2869f98f584","head":{"label":"barryz:go_mem_leak","ref":"go_mem_leak","sha":"e6d87e79d1ffe11fbc8c3935930fc2869f98f584","user":{"login":"barryz","id":16658738,"node_id":"MDQ6VXNlcjE2NjU4NzM4","avatar_url":"https://avatars0.githubusercontent.com/u/16658738?v=4","gravatar_id":"","url":"https://api.github.com/users/barryz","html_url":"https://github.com/barryz","followers_url":"https://api.github.com/users/barryz/followers","following_url":"https://api.github.com/users/barryz/following{/other_user}","gists_url":"https://api.github.com/users/barryz/gists{/gist_id}","starred_url":"https://api.github.com/users/barryz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/barryz/subscriptions","organizations_url":"https://api.github.com/users/barryz/orgs","repos_url":"https://api.github.com/users/barryz/repos","events_url":"https://api.github.com/users/barryz/events{/privacy}","received_events_url":"https://api.github.com/users/barryz/received_events","type":"User","site_admin":false},"repo":{"id":143083986,"node_id":"MDEwOlJlcG9zaXRvcnkxNDMwODM5ODY=","name":"go-bpt","full_name":"barryz/go-bpt","private":false,"owner":{"login":"barryz","id":16658738,"node_id":"MDQ6VXNlcjE2NjU4NzM4","avatar_url":"https://avatars0.githubusercontent.com/u/16658738?v=4","gravatar_id":"","url":"https://api.github.com/users/barryz","html_url":"https://github.com/barryz","followers_url":"https://api.github.com/users/barryz/followers","following_url":"https://api.github.com/users/barryz/following{/other_user}","gists_url":"https://api.github.com/users/barryz/gists{/gist_id}","starred_url":"https://api.github.com/users/barryz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/barryz/subscriptions","organizations_url":"https://api.github.com/users/barryz/orgs","repos_url":"https://api.github.com/users/barryz/repos","events_url":"https://api.github.com/users/barryz/events{/privacy}","received_events_url":"https://api.github.com/users/barryz/received_events","type":"User","site_admin":false},"html_url":"https://github.com/barryz/go-bpt","description":"Chinese translations of Golang related blogs or posts.","fork":false,"url":"https://api.github.com/repos/barryz/go-bpt","forks_url":"https://api.github.com/repos/barryz/go-bpt/forks","keys_url":"https://api.github.com/repos/barryz/go-bpt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/barryz/go-bpt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/barryz/go-bpt/teams","hooks_url":"https://api.github.com/repos/barryz/go-bpt/hooks","issue_events_url":"https://api.github.com/repos/barryz/go-bpt/issues/events{/number}","events_url":"https://api.github.com/repos/barryz/go-bpt/events","assignees_url":"https://api.github.com/repos/barryz/go-bpt/assignees{/user}","branches_url":"https://api.github.com/repos/barryz/go-bpt/branches{/branch}","tags_url":"https://api.github.com/repos/barryz/go-bpt/tags","blobs_url":"https://api.github.com/repos/barryz/go-bpt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/barryz/go-bpt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/barryz/go-bpt/git/refs{/sha}","trees_url":"https://api.github.com/repos/barryz/go-bpt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/barryz/go-bpt/statuses/{sha}","languages_url":"https://api.github.com/repos/barryz/go-bpt/languages","stargazers_url":"https://api.github.com/repos/barryz/go-bpt/stargazers","contributors_url":"https://api.github.com/repos/barryz/go-bpt/contributors","subscribers_url":"https://api.github.com/repos/barryz/go-bpt/subscribers","subscription_url":"https://api.github.com/repos/barryz/go-bpt/subscription","commits_url":"https://api.github.com/repos/barryz/go-bpt/commits{/sha}","git_commits_url":"https://api.github.com/repos/barryz/go-bpt/git/commits{/sha}","comments_url":"https://api.github.com/repos/barryz/go-bpt/comments{/number}","issue_comment_url":"https://api.github.com/repos/barryz/go-bpt/issues/comments{/number}","contents_url":"https://api.github.com/repos/barryz/go-bpt/contents/{+path}","compare_url":"https://api.github.com/repos/barryz/go-bpt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/barryz/go-bpt/merges","archive_url":"https://api.github.com/repos/barryz/go-bpt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/barryz/go-bpt/downloads","issues_url":"https://api.github.com/repos/barryz/go-bpt/issues{/number}","pulls_url":"https://api.github.com/repos/barryz/go-bpt/pulls{/number}","milestones_url":"https://api.github.com/repos/barryz/go-bpt/milestones{/number}","notifications_url":"https://api.github.com/repos/barryz/go-bpt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/barryz/go-bpt/labels{/name}","releases_url":"https://api.github.com/repos/barryz/go-bpt/releases{/id}","deployments_url":"https://api.github.com/repos/barryz/go-bpt/deployments","created_at":"2018-08-01T00:34:06Z","updated_at":"2018-10-29T13:30:09Z","pushed_at":"2018-10-31T06:02:38Z","git_url":"git://github.com/barryz/go-bpt.git","ssh_url":"git@github.com:barryz/go-bpt.git","clone_url":"https://github.com/barryz/go-bpt.git","svn_url":"https://github.com/barryz/go-bpt","homepage":"","size":257,"stargazers_count":4,"watchers_count":4,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":4,"default_branch":"master"}},"base":{"label":"barryz:master","ref":"master","sha":"f495a58c92fd481744172660648b3b0f919a888c","user":{"login":"barryz","id":16658738,"node_id":"MDQ6VXNlcjE2NjU4NzM4","avatar_url":"https://avatars0.githubusercontent.com/u/16658738?v=4","gravatar_id":"","url":"https://api.github.com/users/barryz","html_url":"https://github.com/barryz","followers_url":"https://api.github.com/users/barryz/followers","following_url":"https://api.github.com/users/barryz/following{/other_user}","gists_url":"https://api.github.com/users/barryz/gists{/gist_id}","starred_url":"https://api.github.com/users/barryz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/barryz/subscriptions","organizations_url":"https://api.github.com/users/barryz/orgs","repos_url":"https://api.github.com/users/barryz/repos","events_url":"https://api.github.com/users/barryz/events{/privacy}","received_events_url":"https://api.github.com/users/barryz/received_events","type":"User","site_admin":false},"repo":{"id":143083986,"node_id":"MDEwOlJlcG9zaXRvcnkxNDMwODM5ODY=","name":"go-bpt","full_name":"barryz/go-bpt","private":false,"owner":{"login":"barryz","id":16658738,"node_id":"MDQ6VXNlcjE2NjU4NzM4","avatar_url":"https://avatars0.githubusercontent.com/u/16658738?v=4","gravatar_id":"","url":"https://api.github.com/users/barryz","html_url":"https://github.com/barryz","followers_url":"https://api.github.com/users/barryz/followers","following_url":"https://api.github.com/users/barryz/following{/other_user}","gists_url":"https://api.github.com/users/barryz/gists{/gist_id}","starred_url":"https://api.github.com/users/barryz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/barryz/subscriptions","organizations_url":"https://api.github.com/users/barryz/orgs","repos_url":"https://api.github.com/users/barryz/repos","events_url":"https://api.github.com/users/barryz/events{/privacy}","received_events_url":"https://api.github.com/users/barryz/received_events","type":"User","site_admin":false},"html_url":"https://github.com/barryz/go-bpt","description":"Chinese translations of Golang related blogs or posts.","fork":false,"url":"https://api.github.com/repos/barryz/go-bpt","forks_url":"https://api.github.com/repos/barryz/go-bpt/forks","keys_url":"https://api.github.com/repos/barryz/go-bpt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/barryz/go-bpt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/barryz/go-bpt/teams","hooks_url":"https://api.github.com/repos/barryz/go-bpt/hooks","issue_events_url":"https://api.github.com/repos/barryz/go-bpt/issues/events{/number}","events_url":"https://api.github.com/repos/barryz/go-bpt/events","assignees_url":"https://api.github.com/repos/barryz/go-bpt/assignees{/user}","branches_url":"https://api.github.com/repos/barryz/go-bpt/branches{/branch}","tags_url":"https://api.github.com/repos/barryz/go-bpt/tags","blobs_url":"https://api.github.com/repos/barryz/go-bpt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/barryz/go-bpt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/barryz/go-bpt/git/refs{/sha}","trees_url":"https://api.github.com/repos/barryz/go-bpt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/barryz/go-bpt/statuses/{sha}","languages_url":"https://api.github.com/repos/barryz/go-bpt/languages","stargazers_url":"https://api.github.com/repos/barryz/go-bpt/stargazers","contributors_url":"https://api.github.com/repos/barryz/go-bpt/contributors","subscribers_url":"https://api.github.com/repos/barryz/go-bpt/subscribers","subscription_url":"https://api.github.com/repos/barryz/go-bpt/subscription","commits_url":"https://api.github.com/repos/barryz/go-bpt/commits{/sha}","git_commits_url":"https://api.github.com/repos/barryz/go-bpt/git/commits{/sha}","comments_url":"https://api.github.com/repos/barryz/go-bpt/comments{/number}","issue_comment_url":"https://api.github.com/repos/barryz/go-bpt/issues/comments{/number}","contents_url":"https://api.github.com/repos/barryz/go-bpt/contents/{+path}","compare_url":"https://api.github.com/repos/barryz/go-bpt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/barryz/go-bpt/merges","archive_url":"https://api.github.com/repos/barryz/go-bpt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/barryz/go-bpt/downloads","issues_url":"https://api.github.com/repos/barryz/go-bpt/issues{/number}","pulls_url":"https://api.github.com/repos/barryz/go-bpt/pulls{/number}","milestones_url":"https://api.github.com/repos/barryz/go-bpt/milestones{/number}","notifications_url":"https://api.github.com/repos/barryz/go-bpt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/barryz/go-bpt/labels{/name}","releases_url":"https://api.github.com/repos/barryz/go-bpt/releases{/id}","deployments_url":"https://api.github.com/repos/barryz/go-bpt/deployments","created_at":"2018-08-01T00:34:06Z","updated_at":"2018-10-29T13:30:09Z","pushed_at":"2018-10-31T06:02:38Z","git_url":"git://github.com/barryz/go-bpt.git","ssh_url":"git@github.com:barryz/go-bpt.git","clone_url":"https://github.com/barryz/go-bpt.git","svn_url":"https://github.com/barryz/go-bpt","homepage":"","size":257,"stargazers_count":4,"watchers_count":4,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/barryz/go-bpt/pulls/9"},"html":{"href":"https://github.com/barryz/go-bpt/pull/9"},"issue":{"href":"https://api.github.com/repos/barryz/go-bpt/issues/9"},"comments":{"href":"https://api.github.com/repos/barryz/go-bpt/issues/9/comments"},"review_comments":{"href":"https://api.github.com/repos/barryz/go-bpt/pulls/9/comments"},"review_comment":{"href":"https://api.github.com/repos/barryz/go-bpt/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/barryz/go-bpt/pulls/9/commits"},"statuses":{"href":"https://api.github.com/repos/barryz/go-bpt/statuses/e6d87e79d1ffe11fbc8c3935930fc2869f98f584"}},"author_association":"OWNER"}}
{"actor":{"display_login":"barryz"}}