Jupyter notebooks for your team.

Try free
← Blog

Jupyter Notebook Memory Usage: Check It, Free It After del, and Set a Real Limit (2026)

We measured a Jupyter kernel step by step: an 8-million-row DataFrame of 393 MB took it from 118 MB to 977 MB once the frame and a sorted copy were displayed, and del, gc.collect() and %reset -f out freed nothing. How to see a kernel's memory, why it doesn't come back, the four fixes that worked, and how to set a limit Jupyter will actually enforce.

Fastero Dev TeamFastero Dev Team2026-12-02

We built a notebook that measures its own kernel after every step: create a DataFrame, display it, display a sorted copy, delete it, then try each way of freeing memory people suggest. We ran it in fresh IPython kernels with nbclient on Windows 11 (Python 3.14.3, IPython 9.19.1, ipykernel 7.4.0, pandas 3.1.2, pyarrow 26.0.1), and checked the status-bar extension in JupyterLab 4.6.6.

The short answer: to see how much memory a Jupyter kernel uses, run psutil.Process().memory_info().rss in a cell, or install jupyter-resource-usage, which shows the server's and kernels' memory in the status bar. Memory often doesn't come back after del because IPython keeps every displayed result in Out, _5 and _: in our test del df plus gc.collect() freed nothing, and %reset -f out still left 978 MB. Use %xdel, display(), %reset -f or a kernel restart. Jupyter has no memory limit of its own; JupyterHub, a container or systemd can set one. Checked 2 December 2026.

Fastero

Jupyter notebooks for your team, with nothing to install.

Start a notebook or bring your .ipynb files. SQL cells query your databases with no password in the code, and a notebook runs now or on a schedule. Colleagues open it with their own login; viewers are free.

Try free →

How to check memory usage in a Jupyter notebook

There are four useful views: the whole kernel process, the server and all its kernels, a single line of code, and the variables holding the memory.

From a cell, with psutil

The kernel is an ordinary Python process, so psutil can read its memory. This is the helper our test notebook used:

import os, psutil
 
proc = psutil.Process(os.getpid())
 
def mem(label):
    mb = proc.memory_info().rss / 2**20          # 1 MB here = 1,048,576 bytes
    print(f"{label:<34}{mb:>7,.0f} MB")
 
mem("1. kernel started, pandas loaded")
1. kernel started, pandas loaded      118 MB

rss is the physical memory the process holds: Task Manager's figure on Windows, the RES column of top on Linux. For the memory only this process holds, psutil's docs prefer another number: "uss is probably the most representative metric for determining how much memory is actually being used by a process." memory_full_info().uss gives it, but it's slower and can need higher privileges.

In the status bar, with jupyter-resource-usage

pip install jupyter-resource-usage adds a memory readout to JupyterLab 4 and Notebook 7. Its README says it shows "how much resources your current notebook server and its children (kernels, terminals, etc) are using", refreshing every 5 seconds, and that it reports "the PSS whenever possible (Linux only feature), and default to RSS otherwise." The tachometer icon in the right sidebar opens a Kernel usage panel for the current kernel (it needs ipykernel 6.11 or newer).

JupyterLab 4.6 with a notebook that built a 217 MB DataFrame and displayed a sorted copy; the status bar reads Mem: 750.70 MB / 2.00 GB and the Kernel usage panel shows the kernel itself using 621.91 MB

jupyter-resource-usage 1.3.1 in JupyterLab 4.6.6 on our laptop, with MEM_LIMIT set to 2 GB (displayed, not enforced). We hid one line of the panel that named the machine.

Two things to read correctly. The status bar counts the server plus every kernel (750.70 MB here), while the panel shows one kernel (621.91 MB). And the / 2.00 GB is only a label: the extension "can display a memory limit (but not enforce it)." JupyterHub fills it in through the MEM_LIMIT variable when its spawner supports that; on a laptop you set it yourself or see none.

For one line, with %memit

memory_profiler adds %memit, which reports the process's peak memory while a statement runs and how much that rose. Its README now opens with: "This package is no longer actively maintained." It still works, with one catch we hit: on Python 3.12 or newer, %load_ext memory_profiler fails with a ModuleNotFoundError for distutils. Python 3.12 removed distutils, and its release notes say "The third-party Setuptools package continues to provide distutils", so pip install setuptools in the kernel's environment fixes it.

%load_ext memory_profiler
%memit df.sort_values("amount")
%memit df.rename(columns=str.upper)
%memit df[df["amount"] > 50]
%memit df.groupby("customer")["amount"].sum()
peak memory: 1039.61 MiB, increment: 520.16 MiB
peak memory: 520.31 MiB, increment: 0.02 MiB
peak memory: 765.89 MiB, increment: 245.57 MiB
peak memory: 681.09 MiB, increment: 160.73 MiB

That's on the 393 MB DataFrame from the walkthrough below. Sorting builds a full copy; renaming costs nothing, because pandas 3 copies lazily ("Copy-on-Write is the default and only mode in pandas 3.0"); keeping about half the rows costs about half a copy.

The increment measures how much the process grew, so memory the allocator already holds can hide part of an allocation. In our first run, with nothing released between lines, the same filter reported +92.87 MiB instead of +245.57. For the numbers above we released Arrow's cached memory before each %memit (the release_unused() call in fix 5 below).

Which variables use the most memory

%whos lists variables but not their sizes. This helper ranks DataFrames, Series and arrays in the namespace, including the hidden names IPython creates for displayed results:

import numpy as np, pandas as pd
 
def biggest(ns, top=6):
    found = []
    for name, obj in list(ns.items()):
        if isinstance(obj, pd.DataFrame):
            found.append((obj.memory_usage(deep=True).sum(), name, "DataFrame"))
        elif isinstance(obj, pd.Series):
            found.append((obj.memory_usage(deep=True), name, "Series"))
        elif isinstance(obj, np.ndarray):
            found.append((obj.nbytes, name, "ndarray"))
    for size, name, kind in sorted(found, reverse=True)[:top]:
        print(f"  {name:<6}{size / 2**20:>6,.0f} MB  {kind}")
 
biggest(globals())

Run after del df in our walkthrough, it printed four DataFrames we never named: _5, _, __ and _3. That's the next section. One caution on memory_usage(deep=True): for text columns stored as Python objects it adds up every value separately, even when read_csv reused one string object for all repeats. On a 1-million-row CSV we loaded that way, a column of four region names held just 96 distinct string objects, so its 1 million cells cost about 7.6 MB of pointers, yet deep=True reported 51 MB.

Why memory doesn't come back after del

This is the notebook we ran, with mem() from above called after each step. The DataFrame is invented order data: 8 million rows, five columns, 393 MB by memory_usage(deep=True).

import gc
import numpy as np, pandas as pd, pyarrow as pa
 
def make_orders(n, seed=0):
    rng = np.random.default_rng(seed)
    return pd.DataFrame({
        "order_id": np.arange(n),
        "amount": rng.gamma(2.0, 30.0, n).round(2),
        "quantity": rng.integers(1, 10, n),
        "region": rng.choice(["North", "South", "East", "West"], n),
        "customer": "C" + pd.Series(rng.integers(0, 500_000, n)).astype(str).str.zfill(6),
    })

Then one cell per line, each followed by mem() (after %reset -f, import psutil and define mem() again):

df = make_orders(8_000_000)                 # cell 2: build it
df                                          # cell 3: look at it
df.sort_values("amount", ascending=False)   # cell 5: look at the biggest orders
del df                                      # cell 7
gc.collect()
%reset -f out                               # cell 9
%reset -f                                   # cell 12
pa.default_memory_pool().release_unused()   # cell 13
Step Kernel memory
Kernel started, pandas loaded 118 MB
Created df 592 MB
Displayed df 592 MB
Displayed a sorted copy 977 MB
del df + gc.collect() 977 MB
%reset -f out 978 MB
%reset -f (everything) 550 MB
Arrow's pool release_unused() 123 MB

Line chart of one Jupyter kernel's memory: 118 MB at start, 592 MB after creating a 393 MB DataFrame, 977 MB after displaying a sorted copy, still 977 MB after del and gc.collect(), 978 MB after %reset -f out, 550 MB after %reset -f, and 123 MB after releasing Arrow's memory pool

One kernel's resident memory at each step, measured with psutil on Windows 11. The DataFrame is invented data.

Three separate things kept the memory.

1. IPython's output cache keeps everything you displayed

When a cell ends with an expression, IPython shows it and stores it: in Out[5], in a variable _5, and in _, __ and ___ for the last three results. IPython's docs are blunt about the cost: "This system obviously can potentially put heavy memory demands on your system, since it prevents Python's garbage collector from removing any previously computed results."

So del df removed one name and left Out[3], _3 and __ pointing at the same DataFrame. The sorted copy was never assigned to anything, yet Out[5], _5 and _ kept all 456 MB of it (more than df because its shuffled row index costs 61 MB that the original's default index didn't). Rerun that cell and you keep another copy.

%reset -f out printed Flushing output cache (2 entries) and freed nothing. Checking IPython's hidden namespace afterwards showed why:

{'_': 'DataFrame', '__': 'DataFrame', '___': 'str'}

In IPython 9.19.1, _ and __ still held the sorted copy and df. Only %reset -f, which wipes every variable too, let them go.

2. pandas makes copies, some of them hidden

Every operation that returns new data, like sort_values, a boolean filter or a merge, allocates a new frame, and in a notebook that frame often lands in Out. The %memit lines above show the range: +520 MiB for a sort, +246 MiB for a filter keeping about half the rows, nearly nothing for a rename.

3. The allocator keeps memory it has freed

After %reset -f nothing referenced the data, yet the kernel still held 550 MB. Arrow, which stores pandas 3's text columns when pyarrow is installed, reported its mimalloc pool had 0 MB still allocated: the pool had freed everything and was keeping the memory for reuse. release_unused() handed it back, and the kernel dropped to 123 MB, 5 MB above where it started. The numeric columns, by contrast, went back to Windows as soon as they were freed.

Python's own small-object allocator works the same way. It carves memory into arenas of 1 MiB on 64-bit platforms, and CPython's allocator source returns an arena to the system only when all of its pools are free, so a few surviving objects can pin a whole arena. Which allocator holds what differs by platform (Arrow's docs say its default pool "depends on how Arrow C++ was compiled"), so a Linux kernel shows different numbers, but the pattern of freed-but-held memory is the same.

Jupyter notebooks for your team.

Start free →

How to free memory in Jupyter Notebook

Each of these is something we ran, with the result it gave:

  1. Use %xdel df instead of del df. IPython's docs: it deletes a variable, "trying to clear it from anywhere that IPython's machinery has references to it", output history included. In a fresh kernel, displaying df and then %xdel df took memory from 558 MB to 375 MB and left Out empty.

  2. Show big results with display() or .head(). display(df.sort_values(...)) drew the same table but stored nothing: Out stayed empty, so nothing kept the copy alive once it was on screen.

  3. Use %reset -f when you want a clean slate. It removes every variable and the output history ("removing all references to objects from the current session"). In our run, 978 MB became 550 MB.

  4. Call gc.collect() only for reference cycles. Python frees most objects the moment their last reference goes; the docs note the collector only "supplements the reference counting already used in Python". In our walkthrough it freed nothing, because the problem was live references, not cycles.

  5. Return an allocator's cached memory when you need it back. With pyarrow installed, this took our kernel from 550 MB to 123 MB:

    import pyarrow as pa
    pa.default_memory_pool().release_unused()

    pyarrow's docs warn it "should not be called except potentially for benchmarking or debugging", so use it to free memory for something else, not after every cell.

  6. Restart the kernel. Kernel › Restart Kernel ends the process, and the operating system gets everything back. Load data from a file or query and this costs a rerun, not your work.

  7. Turn off the output cache. Set c.InteractiveShell.cache_size = 0 in ipython_kernel_config.py; IPython's docs say "If you set it to 0, output caching is disabled." We started a kernel with the same setting as a command-line flag, and in it displaying df and its sorted copy stored nothing in Out, and del df brought memory down to 550 MB with no %reset.

The habit that prevents most of this: end cells with .head(), .shape or display(), never with a whole large DataFrame or an expression that builds one. If a kernel keeps dying anyway, why the Jupyter kernel died covers the crash itself, and pandas out of memory covers making the data smaller.

Jupyter notebook memory limit: is there one, and how do you set it?

Jupyter Notebook and JupyterLab have no memory limit of their own. A kernel can use all the RAM the machine has, then swap, and then either an allocation fails with a MemoryError or the operating system kills the process. That's the same in VS Code, where the kernel is also a separate Python process.

Two settings are often mistaken for limits:

  • max_buffer_size, the usual Stack Overflow answer to jupyter notebook increase memory limit. Jupyter Server's docs describe it as "Gets or sets the maximum amount of memory, in bytes, that is allocated for use by the buffer manager", default 536870912. It belongs to the web server, not the kernel, so raising it doesn't give a kernel more memory and lowering it doesn't cap one.
  • jupyter-resource-usage's mem_limit, which only changes the label in the status bar, as above.

These do enforce a limit. We couldn't run them on our Windows laptop, so they come from each project's docs:

Where Jupyter runs Setting What enforces it
JupyterHub c.Spawner.mem_limit = "4G" The spawner, if it supports the setting
Zero to JupyterHub (Kubernetes) singleuser.memory.limit in config.yaml Kubernetes
Docker docker run --memory=4g ... The container's hard limit
A Linux machine with systemd MemoryMax=4G on a systemd-run scope (below) The out-of-memory killer, inside the unit

On Linux with systemd, the scope wraps the whole server and every kernel it starts:

systemd-run --user --scope -p MemoryMax=4G jupyter lab

JupyterHub's docs on mem_limit: "Maximum number of bytes a single-user notebook server is allowed to use", with a catch: "The default spawner, LocalProcessSpawner, does not implement this support." Zero to JupyterHub guarantees each user 1G by default and explains that with a limit set, "requests for more RAM will fail (your kernel will usually die)". Docker's --memory is "The maximum amount of memory the container can use", and systemd's MemoryMax= invokes the out-of-memory killer "inside the unit" when usage can't be kept under it. Our JupyterHub hosting guide covers running a hub.

A limit doesn't make code use less memory; it decides which process dies first. Pair it with the fixes above, and to size the machine itself, see how much RAM you need for data science.

When a notebook needs more memory than you have

Fastero is an AI and data platform where people and AI agents work together on a team's data, and notebooks are part of it: standard .ipynb files, uploaded or imported from the project's Git repository, running on a per-workspace notebook server that nobody has to run.

Everything in this post applies there too. A notebook server runs on 1 CPU and 2 GB as standard. The walkthrough above peaked under 1 GB and fits; a DataFrame a few times bigger, with a copy or two in Out, takes a bigger machine. On the Pro plan a notebook can move to a bigger machine, charged by the second from money added to the balance:

Machine CPUs Memory Price
Standard 1 2 GB Included
Medium 2 8 GB $0.20 an hour
Large 4 16 GB $0.40 an hour
Extra large 8 32 GB $0.80 an hour

So a notebook that needs 16 GB for an afternoon costs $0.40 an hour, rather than a new laptop. Machine time is paid from money you add to the balance, not from Pro's $20 an editor a month. A server stops after about 10 idle minutes, which also hands back whatever the output cache was holding. Notebooks can also run on a cron schedule on the server, with no browser open, and SQL cells hand a query's rows to Python as a DataFrame. Details are on pricing.

FAQ

How do I check memory usage in Jupyter Notebook?

Run psutil.Process().memory_info().rss in a cell for the kernel's own memory, or install jupyter-resource-usage to see the server and kernels in the status bar, refreshed every 5 seconds. For a single statement, %memit from memory_profiler reports the peak and the increase.

Why does my Jupyter notebook use so much memory?

Usually because results you displayed are still stored in Out and in _, __ and _N variables, and because operations like sorting and filtering create full copies. In our test a 393 MB DataFrame and one displayed sorted copy took the kernel to 977 MB.

How do I clear memory in Jupyter without restarting the kernel?

Use %xdel name instead of del name, so IPython's output history lets go too, or %reset -f to clear every variable. Then, if pyarrow is installed, release_unused() on pa.default_memory_pool() returns memory Arrow is holding. In our run that took the kernel from 978 MB to 123 MB.

Does gc.collect() free memory in a Jupyter notebook?

Only memory held in reference cycles. Objects that something still refers to, such as a DataFrame in Out, stay alive however often you call it; in our test it freed nothing after del df.

Does %reset -f out free memory?

It clears Out and the _N variables, but in our run with IPython 9.19.1 the last results stayed reachable through _ and __, and memory didn't move. %xdel, a full %reset -f or a restart did free it.

What is the memory limit of Jupyter Notebook, and how do I increase it?

Jupyter has no limit of its own: the kernel can use the machine's memory. To get more, run the notebook on a machine with more RAM; to cap it, use JupyterHub's mem_limit, a container's --memory or systemd's MemoryMax. max_buffer_size is not a kernel memory setting.

Is the memory limit shown by jupyter-resource-usage enforced?

No. The README says the extension "can display a memory limit (but not enforce it)." JupyterHub passes the real limit to it through MEM_LIMIT, but the enforcing is done by the spawner or the container.

Sources

Read on 2 December 2026. Measurements were made the same day on Windows 11; the JupyterHub, Docker and systemd settings were not run.


Try Fastero free: run your notebooks on a server nobody has to look after, and move one to 8, 16 or 32 GB by the hour when it needs the room. No credit card required.

Start a notebook next to your team's data.

Python 3.11 with pandas, SQLAlchemy and seaborn, SQL cells on your databases, and scheduled runs on the Free plan. No credit card required.

Follow Fastero on LinkedIn for new articles and examples.

Keep reading

Related articles