{"thread":{"id":"4550","subject":"Some more memory leak avoidance","startedAt":"2006-06-18T01:47:58Z","lastAt":"2006-06-18T01:47:58Z","messageCount":1,"participants":["Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"21984","messageId":"Pine.LNX.4.64.0606171836180.5498@g5.osdl.org","threadId":"4550","inReplyTo":null,"subject":"Some more memory leak avoidance","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-06-18T01:47:58Z","receivedAt":"2006-06-18T01:47:58Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nThis is really the dregs of my effort to not waste memory in git-rev-list, \nand makes barely one percent of a difference in the memory footprint, but \nhey, it's also a pretty small patch.\n\nIt discards the parent lists and the commit buffer after the commit has \nbeen shown by git-rev-list (and \"git log\" - which already did the commit \nbuffer part), and frees the commit list entry that was used by the \nrevision walker.\n\nThe big win would be to get rid of the \"refs\" pointer in the object \nstructure (another 5%), because it's only used by fsck. That would require \nsome pretty major surgery to fsck, though, so I'm timid and did the less \ninteresting but much easier part instead.\n\nThis (percentually) makes a bigger difference to \"git log\" and friends, \nsince those are walking _just_ commits, and thus the list entries tend to \nbe a bigger percentage of the memory use. But the \"list all objects\" case \ndoes improve too.\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\n\nThis one should be independent of the other memory use optimizations.\n\n builtin-log.c      |    2 ++\n builtin-rev-list.c |    8 ++++++++\n revision.c         |    6 ++++--\n 3 files changed, 14 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin-log.c b/builtin-log.c\nindex 29a8851..f6da1c3 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -40,6 +40,8 @@ static int cmd_log_wc(int argc, const ch\n \t\tlog_tree_commit(rev, commit);\n \t\tfree(commit->buffer);\n \t\tcommit->buffer = NULL;\n+\t\tfree_commit_list(commit->parents);\n+\t\tcommit->parents = NULL;\n \t}\n \treturn 0;\n }\ndiff --git a/builtin-rev-list.c b/builtin-rev-list.c\nindex 2b298c4..71353eb 100644\n--- a/builtin-rev-list.c\n+++ b/builtin-rev-list.c\n@@ -89,6 +89,14 @@ static void show_commit(struct commit *c\n \t\tprintf(\"%s%c\", pretty_header, hdr_termination);\n \t}\n \tfflush(stdout);\n+\tif (commit->parents) {\n+\t\tfree_commit_list(commit->parents);\n+\t\tcommit->parents = NULL;\n+\t}\n+\tif (commit->buffer) {\n+\t\tfree(commit->buffer);\n+\t\tcommit->buffer = NULL;\n+\t}\n }\n \n static struct object_list **process_blob(struct blob *blob,\ndiff --git a/revision.c b/revision.c\nindex f4b8826..475d604 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -944,9 +944,11 @@ struct commit *get_revision(struct rev_i\n \t}\n \n \tdo {\n-\t\tstruct commit *commit = revs->commits->item;\n+\t\tstruct commit_list *entry = revs->commits;\n+\t\tstruct commit *commit = entry->item;\n \n-\t\trevs->commits = revs->commits->next;\n+\t\trevs->commits = entry->next;\n+\t\tfree(entry);\n \n \t\t/*\n \t\t * If we haven't done the list limiting, we need to look at\n"}]}