File: Debugging%20Memory%20Leaks.md

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (21 lines) | stat: -rw-r--r-- 1,097 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Debugging Memory Leaks

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.

## macOS

At any point during SourceKit-LSP’s execution, you can collect a memory graph using

```bash
leaks --outputGraph=/tmp sourcekit-lsp
```

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).

## Linux

[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.

- Install heaptrack: `apt install heaptrack heaptrack-gui`
- Attach heaptrack to SourceKit-LSP: `heaptrack --record-only --pid $(pidof sourcekit-lsp)`
- Run the command that heaptrack suggests to analyze the file