Title: Memory leak while iterating over commits and their diffs? · Issue #766 · nodegit/nodegit · GitHub
Open Graph Title: Memory leak while iterating over commits and their diffs? · Issue #766 · nodegit/nodegit
X Title: Memory leak while iterating over commits and their diffs? · Issue #766 · nodegit/nodegit
Description: I have some code that iterates over a range of commits and tries to extract some information from each commit (which requires to look at the diff of each commit). For longer histories, this systematically ends up with a process out memor...
Open Graph Description: I have some code that iterates over a range of commits and tries to extract some information from each commit (which requires to look at the diff of each commit). For longer histories, this systema...
X Description: I have some code that iterates over a range of commits and tries to extract some information from each commit (which requires to look at the diff of each commit). For longer histories, this systema...
Opengraph URL: https://github.com/nodegit/nodegit/issues/766
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Memory leak while iterating over commits and their diffs?","articleBody":"I have some code that iterates over a range of commits and tries to extract some information from each commit (which requires to look at the diff of each commit). For longer histories, this systematically ends up with a process out memory error or with a core dump.\n\nI made a modified examples program that triggers it (just put it in nodegit examples directory and run it).\nIt will iterate over the commits and trigger the error.\n\nHere's the code:\n\n``` javascript\nvar nodegit = require(\"../\");\nvar path = require(\"path\");\n\nvar repo;\n\nfunction process(commit) {\n \"use strict\";\n console.log(\"commit \" + commit.sha());\n return commit.getDiff().then(function (diffList) {\n return Promise.all(diffList.map(function (diff) {\n return diff.patches().then(function (patches) {\n return Promise.all(patches.map(function (patch) {\n return patch.hunks().then(function (hunks) {\n return Promise.all(hunks.map(function (hunk) {\n return hunk.lines().then(function (lines) {\n return true;\n });\n }));\n });\n }));\n })\n })).then(function () {\n if(commit.parentcount() === 0) {\n return false;\n } else {\n return repo.getCommit(commit.parentId(0));\n }\n });\n });\n}\n\nfunction iterate(commit) {\n \"use strict\";\n\n return process(commit).then(function(childcommit) {\n if(!childcommit) {\n return true;\n } else {\n return iterate(childcommit);\n }\n });\n}\n\n// This code examines the diffs between a particular commit and all of its\n// parents. Since this commit is not a merge, it only has one parent. This is\n// similar to doing `git show`.\n\nnodegit.Repository.open(path.resolve(__dirname, \"../.git\"))\n .then(function (re) {\n repo = re;\n return repo.getHeadCommit();\n })\n .then(function (commit) {\n return iterate(commit);\n })\n .done(function () {\n \"use strict\";\n console.log(\"done\");\n })\n```\n\nI get an error similar to the following:\n\n```\n\u003c--- Last few GCs ---\u003e\n\n 29305 ms: Scavenge 1398.7 (1457.0) -\u003e 1398.7 (1457.0) MB, 5.0 / 0 ms (+ 1.8 ms in 1 steps since last GC) [allocation failure] [incremental marking delaying mark-sweep].\n 30477 ms: Mark-sweep 1398.7 (1457.0) -\u003e 1398.7 (1457.0) MB, 1172.2 / 5 ms (+ 2.7 ms in 2 steps since start of marking, biggest step 1.8 ms) [last resort gc].\n 31407 ms: Mark-sweep 1398.7 (1457.0) -\u003e 1398.7 (1457.0) MB, 930.4 / 5 ms [last resort gc].\n\n\n\u003c--- JS stacktrace ---\u003e\n\n==== JS stack trace =========================================\n\nSecurity context: 0x72d20d36ae1 \u003cJS Object\u003e\n 1: /* anonymous */(aka /* anonymous */) [/home/jfremy/prog/nodejs/nodegit/node_modules/nodegit-promise/lib/node-extensions.js:24] [pc=0x28f3e3723a14] (this=0x72d20d04131 \u003cundefined\u003e,resolve=0x1460e70041d1 \u003cJS Function done (SharedFunctionInfo 0x30acef4d48d1)\u003e,reject=0x1460e7004189 \u003cJS Function (SharedFunctionInfo 0x30acef4d4979)\u003e)\n 2: tryCallTwo(aka tryCallTwo) [/home/jfremy/prog/nodejs/n...\n\nFATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory\nAbandon (core dumped)\n```\n","author":{"url":"https://github.com/jfremy","@type":"Person","name":"jfremy"},"datePublished":"2015-10-26T14:16:36.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/766/nodegit/issues/766"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:59024154-957e-a3f3-0650-ce6f50f5b489 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CB00:78046:7C29D7:A54ABD:6A6001E1 |
| html-safe-nonce | 266e7f6c2922d6d137fe6947882291bfbfa5a09db479ae49eb454d9bb883fd12 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQjAwOjc4MDQ2OjdDMjlENzpBNTRBQkQ6NkE2MDAxRTEiLCJ2aXNpdG9yX2lkIjoiNjkyMzIyOTUyOTA2NDM0MTk4NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6387d611bd8b07d7fce84d6299f685803dbbbec9ee6d3af3007ee9258e639123 |
| hovercard-subject-tag | issue:113364963 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodegit/nodegit/766/issue_layout |
| twitter:image | https://opengraph.githubassets.com/824b9f01d0215a7fa903e589426c19f0cac3297596d6f05e9d5f16a52b304ced/nodegit/nodegit/issues/766 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/824b9f01d0215a7fa903e589426c19f0cac3297596d6f05e9d5f16a52b304ced/nodegit/nodegit/issues/766 |
| og:image:alt | I have some code that iterates over a range of commits and tries to extract some information from each commit (which requires to look at the diff of each commit). For longer histories, this systema... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jfremy |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5789899e92b20db289de946d86eb20bf5c9626276695d68f58a8c47cdda699b7 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodegit/nodegit git https://github.com/nodegit/nodegit.git |
| octolytics-dimension-user_id | 657068 |
| octolytics-dimension-user_login | nodegit |
| octolytics-dimension-repository_id | 1383170 |
| octolytics-dimension-repository_nwo | nodegit/nodegit |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1383170 |
| octolytics-dimension-repository_network_root_nwo | nodegit/nodegit |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 6ddc048ddf80664b9b33547b619db10313c482f1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width