# Discard Options for Large Heap Dump Analysis

Analyzing heap dumps from large Java applications can be memory-intensive and may result in the analysis tool crashing due to JVM or internal memory limits. To handle such scenarios, HeapHero offers discard options that allow selective or random object removal during heap dump parsing. It helps to complete the analysis successfully. This feature was implemented in version 3.1

# Why Are Discard Options Needed?

When parsing large heap dumps, the JVM may encounter fatal errors like:

java.lang.OutOfMemoryError: Requested length of new long[2,147,483,640] exceeds limit of 2,147,483,639
1

This happens because Java arrays are internally used to track millions or billions of objects, and they have a strict size limit (~2.1 billion elements). The analysis can crash, even with large memory allocations (-Xmx).

To mitigate this, HeapHero introduces discard options that:

  • Reduce the total number of objects retained during parsing
  • Lower memory consumption
  • Ensure the analysis completes successfully

# Discard Options Overview

HeapHero supports two discard-related system properties:

Property Description
discardObjects Randomly discards a percentage of objects globally
discardObjectPattern Discards objects matching a specific class name pattern

These can be used independently or together, depending on your use case

# Option 1: discardObjects (Ratio-based Discarding)

This option allows you to discard a random percentage of objects across the entire heap, which helps reduce memory usage when analyzing very large dumps.

Example Usage:

In your yCrash application’s launch-yc-server.{sh | bat} file, pass the system property as shown below

java -Xms2g -Xmx4g -DlogDir=. -DuploadDir=. -DdiscardObjects="30"
1

This configuration will discard 30% of all objects randomly during heap parsing.

Important Note:

The discardObjectPattern only works if discardObjects is also configured.

  • discardObjectPattern defines what classes can be discarded.
  • discardObjects defines how many (in %) of those matching objects will be discarded

Example Usage:

In your yCrash application’s launch-yc-server.{sh | bat} file, pass system properties as shown below

java -Xms2g -Xmx4g -DlogDir=. -DuploadDir=. -DdiscardObjectPattern=”^(javax|sun|com\.sun|jdk|org\.omg|org\.w3c|org\.xml|org\.ietf|org\.eclipse)\..*|char\[\]|java\.lang\.String” -DdiscardObjects=100
1

This setup discards:

  • All classes from common Java/XML packages (javax.*, org.w3c.*, etc.)
  • Internal JDK classes (sun.*, com.sun.*)
  • char[] arrays (common but low-leak value)
  • char[] arrays and all String objects.

If you configure discardObjectPattern without setting discardObjects, it will have no effect.

# Understanding GC Roots and Discarding

HeapHero does not discard objects reachable from GC roots, even if they match the discard pattern.

# Why?

GC root-referenced objects are critical for maintaining the object graph’s structure. Discarding them could:

  • Break object references
  • Skew retained size calculations
  • Corrupt analysis paths

As a result, reachable objects may still appear in the report even if they match the discard criteria.

# What Happens to Discarded Objects?

  • Discarded objects are not indexed.

  • They will not appear in:

    • Largest objects tables
    • list objects queries (incoming/outgoing references)
  • They may still appear in the "Actual Data" view under Attributes or Statics (if referenced directly).

# Common Configuration Scenarios

The behavior of the discard mechanism depends on how the system properties discardObjectPattern and discardObjects are configured. Below are four typical scenarios to help clarify how these settings interact:

# Scenario 1: Both discardObjectPattern and discardObjects are specified (with discardObjects > 0)

This configuration enables class-based selective discarding. The system will identify all objects whose class names match the provided pattern, and discard up to the specified percentage of those objects.

Example:

-DdiscardObjectPattern=java\.util\..* -DdiscardObjects=50
1

Up to 50% of objects belonging to classes under java.util.* will be discarded during parsing. This is the most effective setup for reducing memory consumption while retaining critical heap structure.

# Scenario 2: Only discardObjects is specified (with no pattern)

This enables random discarding across all heap objects, regardless of class type. It's particularly useful for extremely large heap dumps where broad memory reduction is needed.

Example:

-DdiscardObjects=30
1

Approximately 30% of all objects will be randomly discarded, helping to lower memory usage during heap dump parsing. This approach is class-agnostic and may remove both useful and low-priority objects.

# Scenario 3: discardObjectPattern is specified, but discardObjects is not defined

Providing a pattern without a corresponding discardObjects ratio will have no effect. The pattern acts only as a filter; the ratio determines how many of the matching objects are discarded.

Example:

-DdiscardObjectPattern=char\[\]|java\.lang\.String
1

No objects will be discarded. Since discardObjects is not defined, the discard process is not activated even though a valid pattern is provided.

# Scenario 4: discardObjectPattern is specified, and discardObjects is set to 0

This scenario is logically equivalent to disabling object discarding. Even though a pattern is defined, a discardObjects ratio of 0% prevents any objects from being removed.

Example:

-DdiscardObjectPattern=char\[\]|java\.lang\.String -DdiscardObjects=0
1

Zero objects are discarded. The discard mechanism is effectively turned off, regardless of the pattern specified.