-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[Bug] Memory leak when re-evaluating modified pattern with nested templates #2075
Comments
Hey, thanks for the report! I'll definitely look into what's causing this. There's various issues currently when nesting template types but I wasn't aware of such a massive memory leak |
I'm not sure whether this is related, but after further work on my pattern, memory appears to be ballooning during parsing, and doesn't depend on the pattern data being present at all. My current pattern uses 11.3GB of RAM in plcli when applied to an empty file. After investigating further, it seems to be at least partly because when template parameters are involved, the entire ASTNodeTypeDecl is cloned, including the type parameters. I'm not very familiar with the code's structure and how easy it is to change things, but would it be possible to have template implementations be represented by some object with weak references to the definitions of its type parameters and to the relevant template definition? Here's my current pattern. It seems to be particularly caused by a rather deep nesting of templates: the |
Got a very similar issue with an incredibly small and simple pattern and 3kb file. Here is my pattern:
I am on macOS, and I used the memory trace tool to monitor the usage, it seems to be linearly increasing, with small decreases at times. Slowly but surely, it makes its way to incredibly high usage. Before I had the idea to start the trace, my Mac forced me to close an application or else my system would restart, and ImHex was using 51GB (not a typo) of RAM with that single pattern and the latest version (1.37.4). In my trace, the allocations are also measured per function, so once the analysis finishes I will come back and share where the allocations are happening. There probably is a leak somewhere, and this might not even be the same issue as the ones above. |
Operating System
Linux
What's the issue you encountered?
While putting together a pattern, I noticed that every time I modified the pattern and re-evaluated it, ImHex's memory usage went up by about 4 gigabytes. Over time, this leads to my system running low on RAM.
I have narrowed it down to the
CMDL
struct (quick access withCMDL cmdl @ 0xEC;
) and itsDictInfo<RelPtr<T>>
andListPtr<RelPtr<T>>
fields. TheRelPtr<T>
is an optional relative pointer to aT
, and theListPtr
is a relative pointer to an sized array of T.DictInfo<T>
contains multiple layers ofRelPtr<T>
. ReplacingT
withchar
either prevents the memory increase or reduces it so much I can't measure it. I added[[inline]]
attributes in many places for legibility, but removing these does not resolve the issue. I haven't been able to narrow it down further, and I'm not completely confident that this is the root cause.I've attempted to investigate the issue myself using
-fsanitize
and Valgrind, but neither has given me much insight (a heap dump from Valgrind's "massif" tool identified under 200MB of data, while htop indicated memory usage was over 2GB at the time). I haven't used these tools before though, so I could be doing something wrong. I can at least verify that the issue is there in debug builds on the latest master commit as of this writing.In the meantime, I've resorted to restarting ImHex whenever I notice memory usage is low. My 16GB system with other stuff open can only handle 2 rounds of evaluation with the full pattern, but if I replace the
CMDL
pointer with achar
pointer it's usable.How can the issue be reproduced?
DATA
struct, or even remove the entire thing)ImHex Version
1.36.2 and 2ba7db1
ImHex Build Type
Installation type
Tried imhex-bin off AUR, the nightly AppImage, and a local build
Additional context?
I'm running EndeavourOS with KDE/Wayland on an AMD Ryzen 5 4500U with integrated graphics.
cgfx.zip contains
model.cgfx
(the binary, an intermediate build artifact of one of my projects) andcgfx.hexpat
(the pattern).The text was updated successfully, but these errors were encountered: