How much memory Tesseract uses, measured
104 MB
peak for one 300 dpi book page
Memory follows the pixel count
| Image | Fast model | Best model |
|---|---|---|
| Book page, 150 dpi (1.5 MP) | 62 MB | Not run |
| Receipt photo cut to 3 MP | 77 MB | Not run |
| Book page, 300 dpi (5.9 MP) | 104 MB | 153 MB |
| Receipt photo, 12 MP | 180 MB | 202 MB |
| Book page, 600 dpi (23.6 MP) | 368 MB | 422 MB |
Each number is the peak memory of one tesseract process
on one image, English, the median over the pages. Tesseract 5.5.4 from
Homebrew, on a Mac.
From 300 to 600 dpi, the memory grew 3.5 times. Smaller images grew less.
More pixels cost memory, not words
| Same 3 pages at | Memory | Words in order |
|---|---|---|
| 150 dpi | 63 MB | 94.4% |
| 300 dpi | 105 MB | 94.2% |
| 600 dpi | 368 MB | 93.7% |
The 600 dpi copies are enlarged scans. They took 3.4 times as long and found 3 fewer words.
The receipt photo found 110 true words at 12 MP and at 3 MP, not all the same ones. So shrink big photos before OCR.
Small print is different: it needs the pixels. See best DPI for OCR.
Best adds about 50 MB on book pages
| 10 pages, 300 dpi | Fast | Best |
|---|---|---|
| Seconds a page | 3.0 | 5.0 |
| Words in order | 96.0% | 96.1% |
Best took 47% more memory for one more word in 1,955. On the receipt photo, best found fewer words than fast. More on tessdata_best vs fast.
One process grows fast, then slowly
| Pages in one process | Peak memory |
|---|---|
| 1 | 106 MB |
| 5 | 132 MB |
| 10 | 133 MB |
| 20 | 139 MB |
This is Tesseract's list mode: a text file with one image path on each line.
ls pages/*.jpg > pages.txt
tesseract pages.txt out
The peak grew fast over the first pages, then slowly: 7 MB more from page 5 to 20. That is too few pages to rule out a slow leak.
Plan memory per worker
| pytesseract workers | File paths | Pillow images |
|---|---|---|
| 1 | 125 MB | 180 MB |
| 2 | 229 MB | 299 MB |
Peak of Python and its children, on 10 pages at 300 dpi.
Each worker runs its own tesseract, 103 to 105 MB at the
peak.
Python held about 20 MB with paths, and 77 to 93 MB with Pillow images.
Plan Python once, plus one page's peak for each worker. The core of my code:
from concurrent.futures import ThreadPoolExecutor
import pytesseract
def read(path):
return pytesseract.image_to_string(path, lang="eng")
with ThreadPoolExecutor(2) as ex:
texts = list(ex.map(read, paths))
Paths also keep the dpi. On Linux, set
OMP_THREAD_LIMIT=1 too. Both are on
Tesseract batch processing.
Threads do not change memory
| Thread limit | Peak memory | CPU seconds a page |
|---|---|---|
| 1 | 97 MB | 0.79 |
| 2 | 97 MB | 0.92 |
| Not set | 97 MB | 1.16 |
Set with OMP_THREAD_LIMIT, on the same 3 pages each time.
Ubuntu 24.04 in Docker, limited to 2 CPUs.
Ubuntu's Tesseract 5.3.4 is built with OpenMP. The Homebrew build on
the Mac shows no OpenMP in tesseract --version, so the
setting does nothing there.
Or let Apify hold the memory
Our Apify Actor, PDF to Markdown OCR, runs Tesseract on Apify's servers and returns Markdown. Your machine's memory is not used.
- Default 1 GB a run. You can pick 512 MB to 4 GB.
- At 1 GB it shrinks very large pages before OCR, so the run does not run out of memory.
- At 512 MB it skips its second reader for handwriting and says so in the page warnings.
- $0.006 per OCR page, plus $0.00005 a run at the default 1 GB.
- Runs bill to your Apify account. Files go to Apify's servers.
What I tested, and what I did not
How I tested
- Tesseract 5.5.4 with Leptonica 1.87.0 from Homebrew, on an Apple M5 Max with macOS 26.6.
- Models: eng from tessdata_fast (3.9 MB file) and tessdata_best (14.7 MB file), default page mode.
-
Memory: maximum resident set size from
/usr/bin/time -l. One MB here is 1,048,576 bytes. The peak memory footprint line was about 8 MB lower. -
Workers: the resident memory of Python and its children, added up
from
psabout 8 times a second. - A sum like that can count shared pages twice. My first run of 2 workers with Pillow images read 319 MB with only one tesseract open, so the table shows the rerun.
- Book pages: 10 proofread public domain pages, 300 ppi JPEG, 1,920 pixels wide.
- Their heights: 2,988 to 3,079 pixels.
- The other sizes were made with Pillow as PNG. 600 dpi: the first 3 pages only. MP values are medians.
- Photo: a 3,024 by 4,032 phone photo of a restaurant receipt, from a CC BY 4.0 receipt set.
- Words: true words found in order, after Unicode cleanup.
- Mac seconds: at background priority (nice 19, taskpolicy -b), with up to 3 tesseract processes at once. Compare them only with each other.
Not tested
- Other languages, or several at once, like eng+deu.
- tesserocr or the C++ API in one long process.
- Windows, or Linux on a real server.
- What happens at a hard memory limit below the peak.
- OCRmyPDF, which runs its own workers on PDFs.
Sources
- Tesseract on GitHub, Apache-2.0
- tessdata_fast and tessdata_best
- pytesseract 0.3.13
- Labeled restaurant receipt images, CC BY 4.0
- We make the Apify Actor, not Tesseract.
Questions people ask
How much RAM does Tesseract need?
About 104 MB for one 300 dpi book page with the fast English model. Memory grows with the pixel count of the image, so a larger image needs more.
Does Tesseract use more memory with more threads?
No. On Linux, the peak stayed at 97 MB a page with OMP_THREAD_LIMIT at 1, at 2 and not set. More threads changed the time, not the memory.
Does Tesseract leak memory over many pages?
I saw no clear leak, but 20 pages is a short test. One process read them from a list file. Its peak grew fast at first, then slowly, to 139 MB.