Java heap space Error while accessing Chart.calculate() method

Hi Team,

Cells-Jar used : aspose-cells-21.6.jar

Scenario : We need to access the individual series points of the chart and apply specific properties.

For this we are using chart.calculate() method on the chart.

This internally generating an ArrayList of 20K java.lang.Double objects.

StackTrace :
at java.lang.OutOfMemoryError.()V (
at java.util.Arrays.copyOf([Ljava/lang/Object;I)[Ljava/lang/Object; (
at java.util.ArrayList.grow(I)V (
at java.util.ArrayList.ensureExplicitCapacity(I)V (
at java.util.ArrayList.ensureCapacityInternal(I)V (
at java.util.ArrayList.add(Ljava/lang/Object;)Z (
at com.aspose.cells.b.a.a.zf.a(Ljava/util/ArrayList;Ljava/lang/Object;)I (Unknown Source)
at com.aspose.cells.zkn.b(Lcom/aspose/cells/zck;IDDDLjava/util/ArrayList;DDZZZ)V (Unknown Source)
at com.aspose.cells.zkn.a([DLcom/aspose/cells/zck;Lcom/aspose/cells/zbnq;FIDDDDZZZ)V (Unknown Source)
at com.aspose.cells.zkn.a(Lcom/aspose/cells/zck;DDIFZLcom/aspose/cells/zbnq;ZZZ)V (Unknown Source)
at com.aspose.cells.zkn.a(Lcom/aspose/cells/zkt;)V (Unknown Source)
at com.aspose.cells.zkt.ap()V (Unknown Source)
at com.aspose.cells.zmg.d(Lcom/aspose/cells/Chart;)Lcom/aspose/cells/zkt; (Unknown Source)
at com.aspose.cells.zkr.b(Lcom/aspose/cells/Chart;Z)V (Unknown Source)
at com.aspose.cells.zkr.a(Lcom/aspose/cells/Chart;ZZ)V (Unknown Source)
at com.aspose.cells.Chart.a(ZZ)V (Unknown Source)
at com.aspose.cells.Chart.calculate()V (Unknown Source)

Query : Is there a method to clear this object or any alternatives advisable to use here ?

Note :

  1. The similar issue was not reproducible with aspose-cells-19.11.jar
  2. This is happening in higher environments and couldnt share the related code for the same.

Thanks in advance,

I am afraid that without the sample Excel file and runnable code we cannot assist you further. You may try to create a sample Excel file by replacing any confidential data along with the simplified console application for our reference. You may mark this thread as private before sharing this information as only the authorized personnel here at Aspose can access tprivate data and no public access is granted to anyone else.

Hi @ahsaniqbalsidiqui,

Here by attaching a zip file with a sample code snippet that uses chart.calculate( ) method to access the series points individually to check some range and alter its datalabel text.

The sample I shared will be working as expected without any outofmemory errors (if it is launched for once).

If the same code snippet is common one and executes for multiple times the arraylist intenally is loaded with huge double data values (say 20K).

Is there a way we could clear the list after its usage or any other alternative approch to handle this scenario ?

Note :

  1. Using 19.11 cells jar we never faced this error.
  2. Observed this issue with both 21.5 & 21.6 cells java jars

Thanks in advance,
Sanjeev (22.4 KB)

I have tried to run this application for about 10000 times but could not reproduce this issue. Please explain how are you running this code either is it executed in loop or in parallel? You may try to create some some application that can reproduce the issue. It will help us to observe the issue and provide assistance at the earliest.

Hi @ahsaniqbalsidiqui,

The sample provided earlier has very less no. of series points.
Attaching a new sample with more series points for your reference.

The reports are running in parallel and can have more number of series points.
Probably you can validate the same with samples similar to the one shared newly.

Note :

  1. Java Heap Space size we have is 1GB
  2. Issue is with both 21.5 & 21.6 aspose-cells java jars

Thanks in advance,
Sanjeev (69.2 KB)


I can not reproduce the issue with newly shared data and code. Can you please share OS and JDK details for our analysis.

Hi @ahsaniqbalsidiqui,

Here are the details :
OS : Linux
JDK : jdk1.8.0_121

We have performed Heap Space Consumption analysis on the java code shared in the previous reply.

Using 21.6 cells jar : Heap Space consumption is around 48 MB
HeapSpaceConsumption_Cells_21.6.png (46.9 KB)

Using 19.11 cells jar : Heap Space consumption is only 25 MB
HeapSpaceConsumption_Cells_19.11.png (42.1 KB)

Could you please check on this difference in Heap Space usage.


We have reviewed this information and logged a ticket for further detailed analysis. You will be notified here once any update is ready for sharing.

This issue is logged as:
CELLSJAVA-43518 - Java heap space Error while accessing Chart.calculate() method

We tested the case but cannot find such a significant difference between different versions. After importing the template file, memory cost of 21.6 version is about 12M, 19.11 is about 10M. It is reasonable that the memory cost increases for newer versions because we need to change data models to support more features. While Chart.Calculate(), we found for both versions the maximum used memory is about 58M, so Chart.Calculate() in new version does not impose a heavier burden on memory performance when comparing with 19.11.

When testing the same case many times, the performance data may vary because the mechanism of GC, such as the ArrayList of 20K java.lang.Double objects that you mentioned in the first post. Such kind of data will be removed from the memory by GC after the calculation. You may also try to call GC manually in your code after calling Chart.Calculate() to make sure such kind of data be released as soon as possible. We are afraid we cannot help much with this part.