Skip to content

Commit ab09f1b

Browse files
authored
Merge pull request #1797 from ahoppen/memory-leak-doc
2 parents 12077da + 84967ec commit ab09f1b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Debugging Memory Leaks
2+
3+
https://www.swift.org/documentation/server/guides/memory-leaks-and-usage.html is a good document with instructions on how to debug memory leaks in Swift. Below are some steps tailored to debug SourceKit-LSP.
4+
5+
## macOS
6+
7+
At any point during SourceKit-LSP’s execution, you can collect a memory graph using
8+
9+
```bash
10+
leaks --outputGraph=/tmp sourcekit-lsp
11+
```
12+
13+
This memory graph can then be opened in Xcode to inspect which objects are alive at that point in time and which objects reference them (thus keeping them alive).
14+
15+
## Linux
16+
17+
[heaptrack](https://github.com/KDE/heaptrack) is a helpful tool to monitor memory allocations and leaks. To debug a memory leak on Linux you need to have SourceKit-LSP (and potentially sourcekitd) built from source, because heaptrack requires debug information for the binaries it inspects. To debug a memory issue on Linux.
18+
19+
- Install heaptrack: `apt install heaptrack heaptrack-gui`
20+
- Attach heaptrack to SourceKit-LSP: `heaptrack --record-only --pid $(pidof sourcekit-lsp)`
21+
- Run the command that heaptrack suggests to analyze the file

Contributor Documentation/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ The following documentation documents are primarily intended for developers of S
44

55
- [Background Indexing](Background%20Indexing.md)
66
- [BSP Extension](BSP%20Extensions.md)
7+
- [Debugging Memory Leaks](Debugging%20Memory%20Leaks.md)
78
- [Files To Reindex](Files%20To%20Reindex.md)
89
- [Implementing a BSP server](Implementing%20a%20BSP%20server.md)
910
- [LSP Extensions](LSP%20Extensions.md)

0 commit comments

Comments
 (0)