{"id":23054093,"url":"https://github.com/jamalkaksouri/memory_leak_golang","last_synced_at":"2025-04-03T04:41:02.725Z","repository":{"id":61489377,"uuid":"551949031","full_name":"jamalkaksouri/memory_leak_golang","owner":"jamalkaksouri","description":"Memory leak in Go by example","archived":false,"fork":false,"pushed_at":"2022-10-16T09:09:19.000Z","size":956,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-08T18:45:49.960Z","etag":null,"topics":["go","golang","leak","memory-leak","minikube","pprof"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jamalkaksouri.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-10-15T13:13:51.000Z","updated_at":"2023-07-26T22:55:36.000Z","dependencies_parsed_at":"2022-10-19T22:15:36.654Z","dependency_job_id":null,"html_url":"https://github.com/jamalkaksouri/memory_leak_golang","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamalkaksouri%2Fmemory_leak_golang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamalkaksouri%2Fmemory_leak_golang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamalkaksouri%2Fmemory_leak_golang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamalkaksouri%2Fmemory_leak_golang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamalkaksouri","download_url":"https://codeload.github.com/jamalkaksouri/memory_leak_golang/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246939177,"owners_count":20857916,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","leak","memory-leak","minikube","pprof"],"created_at":"2024-12-16T00:33:38.574Z","updated_at":"2025-04-03T04:41:02.708Z","avatar_url":"https://github.com/jamalkaksouri.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Memory Leak checking in golang service\n\nSometimes, we find pods restarting several times a day without any error. The memory consumption keeps going up, until it reaches the memory limit.\\\nWe have a process to diagnose memory leak for Go services. Tools such as `pprof` and `minikube` can help us find the root cause.\\\nIn this repo, we used the `pprof` tool to detect the memory leaks\n\n## Dependencies\n- Gin framework\n- Graphviz\n\n## Installation Graphviz in windows\n1. Visit the [download location](https://gitlab.com/graphviz/graphviz/-/releases)\n2. Download and run the [32-bit](https://gitlab.com/api/v4/projects/4207231/packages/generic/graphviz-releases/6.0.2/windows_10_cmake_Release_graphviz-install-6.0.2-win32.exe) or [64-bit](https://gitlab.com/api/v4/projects/4207231/packages/generic/graphviz-releases/6.0.2/windows_10_cmake_Release_graphviz-install-6.0.2-win64.exe) exe file.\n3. Ignore any security warnings you might get.\n4. During the installation, make sure you select Add Graphviz top the system PATH for current user.\n5. When the installation is finished, start CMD as an administrator\n6. Run command `dot`\n\n**Note**\nMake sure that during installation checked \"Add Graphviz to the system PATH for current user\"\n\n![](../754680b6a7f66af5318b6deed62a3e8f5c0d34f2.png)\n\n# Usage\n\n1. One time install\n```bash \ngo install github.com/google/pprof@latest\n```\n2. Dump heap to a file(ensure that application is run!-using new terminal)\n```bash \ncurl http://\u003cHOSTNAME\u003e:\u003cPORT\u003e/debug/pprof/heap \u003e heap.out\n```\n3. Use pprof to interact with heap\n```bash \ngo tool pprof heap.out\n```\n4. Inside the new command prompt\n```bash \npng\n```\n\n💡 Everytime for reporting new result you should repeat levels 2,3,4\\\n💡 After run `go run main.go` go to [localhost](http://localhost:8080/append-slice) on browser then repeat previous level\n\n# routes\n\n🔗 **[http://localhost:8080/append-slice](http://localhost:8080/append-slice)**\\\n🔗 **[http://localhost:8080/hanging](http://localhost:8080/hanging)**\\\n🔗 **[http://localhost:8080/streams](http://localhost:8080/streams)**\n\n\n# Tips\nIn the diagram, each box is a function, and each arrow means a function call. The bigger the box, the higher memory usage. From the graph above, the blame goes to runtime function “allocm” (the largest box near the bottom).\nOnce we found which function is causing the problem, we can check how the memory is leaked.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamalkaksouri%2Fmemory_leak_golang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamalkaksouri%2Fmemory_leak_golang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamalkaksouri%2Fmemory_leak_golang/lists"}