question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scala staging not releasing memory

See original GitHub issue

Compiler version

3.0.0

Minimized example

while true do
  run(iGenAnExpr)

Output

Lots of stuff in the JVM’s old gen heap

Expectation

Thrown away compiled code is freed.

@nicolasstucki

I believe the issue is in the QuotesDriver. In the above code, I generate a lot of code via runtime MSP, and then never use it. I had thought this would result in memory being freed, but apparently there’s some long-lived storage in the compiler that I haven’t found yet, because the above example causes old gen to rapidly fill.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:18 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
smartercommented, Jun 3, 2021

Calling reset on the base context is not enough, the leak comes from val definitions.

More precisely it comes from the baseTypeCache of some denotations: https://github.com/lampepfl/dotty/issues/12543#issuecomment-849607084 which could be turned into a WeahHashMap (and also maybe shouldn’t cache termrefs at all?)

0reactions
nicolasstuckicommented, Jun 3, 2021

Not sure if we should change anything in the caching mechanism for staging. It provides the flexibility to either cache and run fast, or not cache and run a bit slower without consuming to much memory.

The optimizations we should be looking at are in the Context itself which are things that also affect the normal compiler. I saw may trees retained which are probably trees attached to symbols, these could in theory be dropped and recomputed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Releasing Scala Object resources - Stack Overflow
Problem is if anyone puts objects into the sandbox code even though all the classes are easily cleaned up, the objects, and any...
Read more >
Spark SQL Job stcuk indefinitely at last task of a stage
It executes 72 stages successfully but hangs at 499th task of 73rd stage, and not able to execute the final stage no 74....
Read more >
Spark Out of Memory - Criteo Engineering
Our best hypothesis is that we have a memory leak. So we decided to plot the memory consumption of our executors and check...
Read more >
JVM memory management. How to find and prevent ... - Scalac
It's harder to cause a memory leak in JVM than e.g in C, but possible. Let's take a look at useful JVM memory...
Read more >
Troubleshoot Dataflow errors - Google Cloud
To resolve this issue, have your destination, source, and staging ... occurs if the pipeline is using Java Native Interface (JNI) to run...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found