{"action":"created","comment":{"url":"https://api.github.com/repos/apache/incubator-mxnet/pulls/comments/194851374","pull_request_review_id":128102387,"id":194851374,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5NDg1MTM3NA==","diff_hunk":"@@ -224,13 +224,24 @@ class FeedForward private(\n     var i = 0\n     while (data.hasNext && i != numBatch) {\n       val batch = data.next()\n-      i += 1\n-      ExecutorManager.loadData(batch, dataArrays)\n-      predExec.forward(isTrain = false)\n-      val padded = batch.pad\n-      val realSize = batchSize - padded\n-      for ((list, nd) <- outputs zip predExec.outputs) {\n-        list += nd.slice(0, realSize).copy()\n+      try {\n+        i += 1\n+        ExecutorManager.loadData(batch, dataArrays)\n+        predExec.forward(isTrain = false)\n+        val padded = batch.pad\n+        val realSize = batchSize - padded\n+        for ((list, nd) <- outputs zip predExec.outputs) {\n+          // The slice is being written to a value so that dispose can be called after the copy.\n+          // The one liner nd.slice().copy() leads to leaking the memory of the slice.\n+          val ndSliced = nd.slice(0, realSize)\n+          try {\n+            list += ndSliced.copy()\n+          } finally {\n+            ndSliced.dispose()\n+          }\n+        }\n+      } finally {\n+        batch.dispose()","path":"scala-package/core/src/main/scala/org/apache/mxnet/FeedForward.scala","position":28,"original_position":28,"commit_id":"6e00d623fb3e999556070a5bec20e2f9a3c6fc99","original_commit_id":"6e00d623fb3e999556070a5bec20e2f9a3c6fc99","user":{"login":"andrewfayres","id":13068555,"node_id":"MDQ6VXNlcjEzMDY4NTU1","avatar_url":"https://avatars1.githubusercontent.com/u/13068555?v=4","gravatar_id":"","url":"https://api.github.com/users/andrewfayres","html_url":"https://github.com/andrewfayres","followers_url":"https://api.github.com/users/andrewfayres/followers","following_url":"https://api.github.com/users/andrewfayres/following{/other_user}","gists_url":"https://api.github.com/users/andrewfayres/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewfayres/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewfayres/subscriptions","organizations_url":"https://api.github.com/users/andrewfayres/orgs","repos_url":"https://api.github.com/users/andrewfayres/repos","events_url":"https://api.github.com/users/andrewfayres/events{/privacy}","received_events_url":"https://api.github.com/users/andrewfayres/received_events","type":"User","site_admin":false},"body":"Summarizing the conversation we had offline: It appears that the copyTo in loadData is copying to memory in the Executor predExec. The memory in the executor seems to get reused across predict calls. I think that the proper place to dispose of this part would be to add a dispose method for FeedForward and have that dispose of it's predExec.","created_at":"2018-06-12T18:53:39Z","updated_at":"2018-06-12T18:53:39Z","html_url":"https://github.com/apache/incubator-mxnet/pull/11204#discussion_r194851374","pull_request_url":"https://api.github.com/repos/apache/incubator-mxnet/pulls/11204","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-mxnet/pulls/comments/194851374"},"html":{"href":"https://github.com/apache/incubator-mxnet/pull/11204#discussion_r194851374"},"pull_request":{"href":"https://api.github.com/repos/apache/incubator-mxnet/pulls/11204"}},"in_reply_to_id":194773876},"pull_request":{"url":"https://api.github.com/repos/apache/incubator-mxnet/pulls/11204","id":193682811,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkzNjgyODEx","html_url":"https://github.com/apache/incubator-mxnet/pull/11204","diff_url":"https://github.com/apache/incubator-mxnet/pull/11204.diff","patch_url":"https://github.com/apache/incubator-mxnet/pull/11204.patch","issue_url":"https://api.github.com/repos/apache/incubator-mxnet/issues/11204","number":11204,"state":"open","locked":false,"title":"Scala inference memory leak fix","user":{"login":"andrewfayres","id":13068555,"node_id":"MDQ6VXNlcjEzMDY4NTU1","avatar_url":"https://avatars1.githubusercontent.com/u/13068555?v=4","gravatar_id":"","url":"https://api.github.com/users/andrewfayres","html_url":"https://github.com/andrewfayres","followers_url":"https://api.github.com/users/andrewfayres/followers","following_url":"https://api.github.com/users/andrewfayres/following{/other_user}","gists_url":"https://api.github.com/users/andrewfayres/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewfayres/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewfayres/subscriptions","organizations_url":"https://api.github.com/users/andrewfayres/orgs","repos_url":"https://api.github.com/users/andrewfayres/repos","events_url":"https://api.github.com/users/andrewfayres/events{/privacy}","received_events_url":"https://api.github.com/users/andrewfayres/received_events","type":"User","site_admin":false},"body":"## Description ##\r\nThis fixes a memory leak that results from the FeedForward.predict method not properly disposing of the results from NDArray.slice().\r\n\r\n## Testing ##\r\n### Verifying leak exists ###\r\nTo verify that there was a leak in the existing code I created and trained a basic model off of MNIST data then called the predict method inside a while(true) loop then monitored the process's memory usage.\r\n\r\n### Verifying leak fix ###\r\nAfter making the code changes, I repeated the process I had used to verify there was a leak. Memory consumption was much improved and looks to be stable.\r\n\r\n### More testing ###\r\nIn addition to the tests I ran to monitor memory usage, I also ran the existing tests with 'make scalatest'. All tests pass. \r\n\r\n## Checklist ##\r\n### Essentials ###\r\nPlease feel free to remove inapplicable items for your PR.\r\n- [x] The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant [JIRA issue](https://issues.apache.org/jira/projects/MXNET/issues) created (except PRs with tiny changes)\r\n- [x] Changes are complete (i.e. I finished coding on this PR)\r\n- [x] All changes have test coverage:\r\n- Unit tests are added for small changes to verify correctness (e.g. adding a new operator)\r\n- Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)\r\n- Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)\r\n- [x] Code is well-documented: \r\n- For user-facing API changes, API doc string has been updated. \r\n- For new C++ functions in header files, their functionalities and arguments are documented. \r\n- For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable\r\n- Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html\r\n- [x] To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change\r\n","created_at":"2018-06-08T17:54:34Z","updated_at":"2018-06-12T18:53:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d4bb3eb1c0b6a9e192b998751526487b0c9f5be1","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/incubator-mxnet/pulls/11204/commits","review_comments_url":"https://api.github.com/repos/apache/incubator-mxnet/pulls/11204/comments","review_comment_url":"https://api.github.com/repos/apache/incubator-mxnet/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/incubator-mxnet/issues/11204/comments","statuses_url":"https://api.github.com/repos/apache/incubator-mxnet/statuses/6e00d623fb3e999556070a5bec20e2f9a3c6fc99","head":{"label":"andrewfayres:master","ref":"master","sha":"6e00d623fb3e999556070a5bec20e2f9a3c6fc99","user":{"login":"andrewfayres","id":13068555,"node_id":"MDQ6VXNlcjEzMDY4NTU1","avatar_url":"https://avatars1.githubusercontent.com/u/13068555?v=4","gravatar_id":"","url":"https://api.github.com/users/andrewfayres","html_url":"https://github.com/andrewfayres","followers_url":"https://api.github.com/users/andrewfayres/followers","following_url":"https://api.github.com/users/andrewfayres/following{/other_user}","gists_url":"https://api.github.com/users/andrewfayres/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewfayres/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewfayres/subscriptions","organizations_url":"https://api.github.com/users/andrewfayres/orgs","repos_url":"https://api.github.com/users/andrewfayres/repos","events_url":"https://api.github.com/users/andrewfayres/events{/privacy}","received_events_url":"https://api.github.com/users/andrewfayres/received_events","type":"User","site_admin":false},"repo":{"id":131324578,"node_id":"MDEwOlJlcG9zaXRvcnkxMzEzMjQ1Nzg=","name":"incubator-mxnet","full_name":"andrewfayres/incubator-mxnet","owner":{"login":"andrewfayres","id":13068555,"node_id":"MDQ6VXNlcjEzMDY4NTU1","avatar_url":"https://avatars1.githubusercontent.com/u/13068555?v=4","gravatar_id":"","url":"https://api.github.com/users/andrewfayres","html_url":"https://github.com/andrewfayres","followers_url":"https://api.github.com/users/andrewfayres/followers","following_url":"https://api.github.com/users/andrewfayres/following{/other_user}","gists_url":"https://api.github.com/users/andrewfayres/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewfayres/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewfayres/subscriptions","organizations_url":"https://api.github.com/users/andrewfayres/orgs","repos_url":"https://api.github.com/users/andrewfayres/repos","events_url":"https://api.github.com/users/andrewfayres/events{/privacy}","received_events_url":"https://api.github.com/users/andrewfayres/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/andrewfayres/incubator-mxnet","description":"Lightweight, Portable, Flexible Distributed/Mobile Deep Learning with Dynamic, Mutation-aware Dataflow Dep Scheduler; for Python, R, Julia, Scala, Go, Javascript and more","fork":true,"url":"https://api.github.com/repos/andrewfayres/incubator-mxnet","forks_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/forks","keys_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/teams","hooks_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/hooks","issue_events_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/issues/events{/number}","events_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/events","assignees_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/assignees{/user}","branches_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/branches{/branch}","tags_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/tags","blobs_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/git/refs{/sha}","trees_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/statuses/{sha}","languages_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/languages","stargazers_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/stargazers","contributors_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/contributors","subscribers_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/subscribers","subscription_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/subscription","commits_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/commits{/sha}","git_commits_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/git/commits{/sha}","comments_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/comments{/number}","issue_comment_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/issues/comments{/number}","contents_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/contents/{+path}","compare_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/merges","archive_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/downloads","issues_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/issues{/number}","pulls_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/pulls{/number}","milestones_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/milestones{/number}","notifications_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/labels{/name}","releases_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/releases{/id}","deployments_url":"https://api.github.com/repos/andrewfayres/incubator-mxnet/deployments","created_at":"2018-04-27T17:10:37Z","updated_at":"2018-06-11T18:53:58Z","pushed_at":"2018-06-11T18:53:54Z","git_url":"git://github.com/andrewfayres/incubator-mxnet.git","ssh_url":"git@github.com:andrewfayres/incubator-mxnet.git","clone_url":"https://github.com/andrewfayres/incubator-mxnet.git","svn_url":"https://github.com/andrewfayres/incubator-mxnet","homepage":"http://mxnet.io","size":36942,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"b434b8ec18f774c99b0830bd3ca66859212b4911","user":{"login":"apache","id":47359,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ3MzU5","avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":34864402,"node_id":"MDEwOlJlcG9zaXRvcnkzNDg2NDQwMg==","name":"incubator-mxnet","full_name":"apache/incubator-mxnet","owner":{"login":"apache","id":47359,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ3MzU5","avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/incubator-mxnet","description":"Lightweight, Portable, Flexible Distributed/Mobile Deep Learning with Dynamic, Mutation-aware Dataflow Dep Scheduler; for Python, R, Julia, Scala, Go, Javascript and more","fork":false,"url":"https://api.github.com/repos/apache/incubator-mxnet","forks_url":"https://api.github.com/repos/apache/incubator-mxnet/forks","keys_url":"https://api.github.com/repos/apache/incubator-mxnet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/incubator-mxnet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/incubator-mxnet/teams","hooks_url":"https://api.github.com/repos/apache/incubator-mxnet/hooks","issue_events_url":"https://api.github.com/repos/apache/incubator-mxnet/issues/events{/number}","events_url":"https://api.github.com/repos/apache/incubator-mxnet/events","assignees_url":"https://api.github.com/repos/apache/incubator-mxnet/assignees{/user}","branches_url":"https://api.github.com/repos/apache/incubator-mxnet/branches{/branch}","tags_url":"https://api.github.com/repos/apache/incubator-mxnet/tags","blobs_url":"https://api.github.com/repos/apache/incubator-mxnet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/incubator-mxnet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/incubator-mxnet/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/incubator-mxnet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/incubator-mxnet/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/incubator-mxnet/languages","stargazers_url":"https://api.github.com/repos/apache/incubator-mxnet/stargazers","contributors_url":"https://api.github.com/repos/apache/incubator-mxnet/contributors","subscribers_url":"https://api.github.com/repos/apache/incubator-mxnet/subscribers","subscription_url":"https://api.github.com/repos/apache/incubator-mxnet/subscription","commits_url":"https://api.github.com/repos/apache/incubator-mxnet/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/incubator-mxnet/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/incubator-mxnet/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/incubator-mxnet/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/incubator-mxnet/contents/{+path}","compare_url":"https://api.github.com/repos/apache/incubator-mxnet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/incubator-mxnet/merges","archive_url":"https://api.github.com/repos/apache/incubator-mxnet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/incubator-mxnet/downloads","issues_url":"https://api.github.com/repos/apache/incubator-mxnet/issues{/number}","pulls_url":"https://api.github.com/repos/apache/incubator-mxnet/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/incubator-mxnet/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/incubator-mxnet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/incubator-mxnet/labels{/name}","releases_url":"https://api.github.com/repos/apache/incubator-mxnet/releases{/id}","deployments_url":"https://api.github.com/repos/apache/incubator-mxnet/deployments","created_at":"2015-04-30T16:21:15Z","updated_at":"2018-06-12T17:17:09Z","pushed_at":"2018-06-12T18:52:24Z","git_url":"git://github.com/apache/incubator-mxnet.git","ssh_url":"git@github.com:apache/incubator-mxnet.git","clone_url":"https://github.com/apache/incubator-mxnet.git","svn_url":"https://github.com/apache/incubator-mxnet","homepage":"https://mxnet.apache.org","size":37177,"stargazers_count":14164,"watchers_count":14164,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5221,"mirror_url":null,"archived":false,"open_issues_count":967,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":5221,"open_issues":967,"watchers":14164,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-mxnet/pulls/11204"},"html":{"href":"https://github.com/apache/incubator-mxnet/pull/11204"},"issue":{"href":"https://api.github.com/repos/apache/incubator-mxnet/issues/11204"},"comments":{"href":"https://api.github.com/repos/apache/incubator-mxnet/issues/11204/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/incubator-mxnet/pulls/11204/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/incubator-mxnet/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/incubator-mxnet/pulls/11204/commits"},"statuses":{"href":"https://api.github.com/repos/apache/incubator-mxnet/statuses/6e00d623fb3e999556070a5bec20e2f9a3c6fc99"}},"author_association":"NONE"}}
{"actor":{"display_login":"andrewfayres"}}