# How to Fix "Out of Memory" / "Java Heap Space" Errors in Teamscale

If you face a memory-related problem in Teamscale, this article may help you to remedy the issue.

# Problem Description

Teamscale is running out of memory while fetching data or analyzing the code (often after a drastic slow-down due to the JVM trying to free memory) . A line similar to this one appears in the log files or the worker log:

java.io.IOException: java.lang.OutOfMemoryError: Java heap space

# Addressing the Memory Problems

# First: Exclude all Generated Code Requires Re-Analysis

The main source of problems when Teamscale runs out of memory is when the clone detection tries to find clones on large chunks of generated (often highly similar) code. Therefore, the first solution should be to exclude any generated code in the project you are analyzing. For that, you will need to edit the configuration of the affected project.

  • Using path patterns:

    For example, to exclude all code that lives in the folder gen-src, use the following exclude patterns on the Excluded File Names project setting: **/gen-src/**

    The exclusion patterns are regular ant include patters

  • Using file content patterns:

    If excluding code by using directory structures does not work, you can use the advanced field Content Exclude. Use this to exclude files by their content, using regular expressions. For example to exclude all files that contain the documentation string generated by Visual Studio, add the pattern: .*generated by Visual Studio.*

Re-Analysis Required

Please note that changes to these project options will require a re-analysis of the project.

# Second: Adjust Memory Settings Requires Restart

If you have excluded all your generated source code and Teamscale still runs out of memory, you can adjust the amount of memory used by Teamscale.

# Reserving Additional Memory

This can be done by editing $TEAMSCALE_HOME/config/jvm.properties file. Adjust the value of the JVM_MEMORY parameter, for example by reserving up to 16 gigabyes of RAM: JVM_MEMORY=16G

# Reducing the Number of Workers

If your Teamscale server does not have more memory that ought to be reserved, you can also adjust the number of workers that Teamscale should use. This can be done in the teamscale.properties (config folder) via the engine.workers property.

Performance Impact

Note that this will likely slow down the analysis, as Teamscale can parallelize less processes.

As a rule of thumb, we recommend to reserve 2 GB of memory for each Teamscale worker. However, due to varying analysis setups, this is only the lower bound to keep in mind.

# Still Experiencing Problems?

In case Teamscale's analysis is still affected by out-of-memory problems, please don't hesitate to contact our support.