-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak when running multiple sessions #1165
Comments
Addendum, it's definitely the for i in 0..=10 {
session.run(&mut status).expect("Compiling TeX");
} the memory grows like this
(notice that 75 MiB was more or less what I got before for So after rendering 1k times this \documentclass{article}
\begin{document}
hello
\end{document} memory usage is up to a bit more than 1 GiB. |
I've looked into this to try to get the fuzzer infrastructure working well — it complains about leaks since it also expects to run the main code thousands of times. If I remember correctly, the low-hanging fruit should be dealt with. I believe that I saw a lingering leak relating to system fonts — basically, information about which system fonts are being used ends up scattered around TeX's main memory in an extremely inconvenient way. The traditional engine, which expects to run once and quit, doesn't care, but the situation makes cleanup hard here. I think that one would have to add an extra data structure to keep track of these allocations and enable their cleanup upon engine shutdown. (Potentially a nice fit for #1138?) Another area that can cause problems is when the engine errors out, since execution aborts in the middle of who-knows-where inside the code. But that might not be so relevant here. Valgrind is extremely useful for tracking this stuff down in detail. |
For what it's worth, the leak only happens when using |
In my look into xetex_layout, and by extension bits of the actual xetex engine, I can say that I've definitely what look like various dangling allocations in certain scenarios. If it's PDF specific, the issues may lie in pdf_io, but I haven't touched that code yet so can't say for sure. It may simply be the way the engine runs in certain scenarios. |
It seems that when running multiple times a PDF rendering within the same process, there is a pretty bad memory leak. I've been able to reproduce with a relatively minimal example that compiles some very basic inline TeX, no extra packages used. The leak occurs the moment the session is
.run()
- removing that line causes the leak to go away.My context is that I want to use
tectonic
to render PDFs inside a web service (related to the discussion in here). I noticed the leak in there, but obviously this doesn't work there.This is the
Cargo.toml
of the minimal example to reproduce, which uses the most recently available versions (although the problem also arises in e.g. 0.14 or in other minor versions of the dependency crates).And this is the code that showcases the memory leak
which outputs
This specific test was on debian bookworm, but I first noticed inside a Docker image based on alpine, so I doubt it's related to the underlying libs. The leak is quite bad and it gets worse if e.g. the document includes images, which I haven't done in the example for the sake of simplicity.
As for why creating a
Bundle
and aSession
every time, the.into_file_data()
of the ProcessingSession consumes the session, which means I cannot reuse the session for multiple runs. The.bundle()
method of ProcessingSessionBuilder consumes the bundle, and the.create()
method consumes theProcessingSession
too. It seems ownership is required all the way from creating the bundle to getting the PDF, and it doesn't look like it can be worked around.The text was updated successfully, but these errors were encountered: