# What is stored in the kernel's memory

I disabled "Show Suggestions Bar after last output" in the preferences. I begin my code with \$HistoryLength = 0. After running my code, I run the following.

ClearSystemCache[];
Share[];
Remove["Global*"];


However, MemoryInUse[] reveals that the kernal still takes up a few gigabytes of memory. What is stored in the kernel? Other than Quit[], what commands can free up most of the memory?

• Are you sure that's gigabytes? For me, a fresh kernel starts off with 41254400 bytes, or 39.3 MB. How much data have you generated in expressions between your two code blocks? – 2012rcampion Apr 7 '15 at 0:31
• Mine starts with 70577952 bytes, and end with 5100297040 bytes. I do not expect so much memory to be used. Even if there is any memory leak in my code, I have expected the commands in the OP to free up most of the memory. – anon Apr 7 '15 at 0:43
• Just for experimental purposes, what do you get after doing 'Unprotect[In, Out]; Clear[In, Out]'? – ciao Apr 7 '15 at 0:56
• @rasher I actually tried that before. No noticeable change. – anon Apr 7 '15 at 0:57
• I don't know the kernel's architecture so I'm guessing here but I would imagine that the kernel only loads some code and initializes some internal data structures when they're called for. So if your code uses different functions you may end up with different resting memory. If I know I'm going hiking I put my hiking boots in my car, when I get back I probably don't take them out until I clean my car. – Ymareth Apr 7 '15 at 8:37

The large amount of memory used appears to arise from an internal memory leak from MemberQ`. Hence, typical methods of clearing the kernel memory do not work as expected in this situation as long as the bug persists.