Sublime Forum

Leaky thread; huge memory usage (Linux)

#1

Linux 64 bit
Build 3114 (and earlier builds)

Each time that a file is opened in Sublime Text, an additional 8 MB of writable private memory is taken from the OS. When using ST3 extensively, this can cause an explosion in memory.

I have traced this down to a memory leak due to improper pthread termination.
Whatever thread starts at location 0x4bc7b1 (it runs each time you open a new file) that runs for only a small amount of time gets allocated an 8MB stack. Unfortunately, without calling pthread_detach and/or pthread_exit, it appears that the stack memory is not freed up.

“Fix” method:
-LD_PRELOAD a library
-Override pthread_create
-call pthread_detach if the start_routine is 0x4bc7b1
-insert a different start routine which calls 0x4bc7b1 if applicable. end the start routine with a call to pthread_exit

And no more continual 8MB allocation (it can figure out how to reuse that 8MB stack chunk!)

Edit: It appears that one can intercept all start routines, and after calling the original routine, add a pthread_detach(pthread_self()); and pthread_exit(0); No worrying about grabbing the right pthread now!

0 Likes

#2

Is this in a clean state without any third-party packages?

0 Likes

#3

I’ll have to check tomorrow - it’s on my box at work. I had tried adding in third-party utilities through Package Control on a prior build, but since I was behind a highly-limiting proxy, I don’t believe I ever got any successfully installed.

This time around I replaced the sublime_text_3 folder with the contents of the 64 bit build. So I probably have some personal config settings in there.

Note that even without this modification, the threads would still terminate. They just wouldn’t give up their memory.

P.S. Linux = SLES 11

0 Likes

#4

Package Control is the only thing installed…and barely, at that. I have no ability to even search for new packages due to the proxy environment.

subl_fix.c

0 Likes

#5

Thanks for the report, will fix for the next build

0 Likes