Sublime Forum

Sublime Text 4180 memory leak (and high usage)

#1

platform: windows 7 x64
sublime text version: sublime_text_build_4180_x64

this issue may be relate to syntax engine (tested with javascript files).

  • file a.js: simple file with content generated by default ‘for’ snippet:

for (var i = Things.length - 1; i >= 0; i–) {
Things[i]
}

  • file main.js: come from cpptools of Visual Studio Code: you can find it as “\cpptools\dist\src\main.js”, the file size is ~5.39MB; (can be extracted from cpptools-windows-x64.vsix)
  • file test.js: repeat the content of a.js to match the size of main.js.

reproduce:

  1. download https://www.sublimetext.com/download_thanks?target=win-x64-portable;
  2. launch sublime_text.exe to let it initialize something (e.g. create package caches);
  3. close and re-launch sublime, use taskmgr.exe to record its commit memory usage, this is ~22.5 MB in my laptop;
  4. then open a.js, record again the commit memory usage: ~25.8 MB;
  5. then open test.js, the memory usage will be: ~54 MB;
  6. close test.js, see that the memory usage will be: ~24.4 MB;

  1. close and re-launch sublime, record commit memory usage for this fresh instance: ~23 MB;
  2. then open a.js, memory usage will be: ~23.6 MB;
  3. then open main.js, memory usage will be: ~124.6 MB;
  4. finally close main.js, the memory usage remains at: ~122.3 MB;

the expected behavior is:
a) the memory usage return to <25 MB after close main.js;
b) the memory usage for syntax-highlighting of main.js is too high compared to test.js;

0 Likes

#2
  1. In many cases it is up to the operating system to free up used heap memory again. The memory might already be freed up by ST but the heap chunk was not yet reclaimed by Windows. It will do so only on certain triggers such as running out of memory situations.

  2. A memory leak would mean ST’s memory foot print to grow constantly when opening main.js again and again. What happens is it moving from 145MB to 174MB and back to 145MB whenever main is opened and closed again.

    This indicates more of a ST allocated a pease of memory for something it finds useful to keep available.

  3. The provided example compares apples with oranges. Main.ts contains hundreds or even thousands of functions and other entities which are added to symbol list and/or index, while thousands of simple for loops don’t.

    And that’s probably already the answer for why memory footprint stays at 145MB. It is most likely just the required RAM to hold ST’s local symbols and global symbol index.

0 Likes