Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Out of Memory Error : Java heap space

    Hi, I'm trying to export summary statistics from Stata 15.1 to a word document using the putdocx command. However after typing the command
    Code:
    putdocx table Table4=data(unique*), varnames
    , I get the error message "java.lang.OutOfMemoryError: Java heap space".

    Is there any way for me to clear up memory in Stata? My data set has only 10,000 observations.


    Thanks!

  • #2
    You can increase the amount of memory available to Java. On a 64 bit system with 64 bit Stata this a safe thing to do, but when using 32 bit Stata, you need to be careful. That is because the address space for the memory available to Stata is limited for 32 bit processes. As you increases the memory available to Java on 32 bit Stata, you are effectively taking it from other uses in Stata such as for dataset or matrix allocation. By now most people should be using 64 bit Stata. In Stata 15 we allocate 128 megabytes to Java on 32 bit systems and we allocate 384 megabytes to Java on 64 bit systems. The allocation only happens if you use a feature that requires Java, such as putdocx, import delimited, import fred, the project manager, etc. You can get information about Java with query java, including if Java has been initialized.

    Code:
    . query java
    -------------------------------------------------------------------------------
        Java system information
          Java initialized     no
        Advanced Java settings
          set java_heapmax     384m
          set java_vmpath      C:\Program Files (x86)\Stata15\utilities\java\window
    > s-x64\jre1.8.0_162\bin\server\jvm.dll
    If you have 32 bit Stata you might try doubling the allocation to 256 megabytes.

    Code:
    set java_heapmax 256m
    If you have 64 bit Stata I would set the memory to 1 gigabyte.

    Code:
    set java_heapmax 1g
    To find out if you have 32 bit or 64 bit Stata...

    Code:
    . about
    
    Stata/SE 15.1 for Windows (64-bit x86-64)
    Revision 06 Jun 2018
    Copyright 1985-2017 StataCorp LLC
    To set the java_heapmax back to the default you can...

    Code:
    . set java_heapmax
    (java_heapmax preference reset to default)
    Anytime you change a Java setting it will require you to restart Stata to take effect, but only if Java has been initialized. You can refer to query java to see if Java has been initialized, but the set commands will prompt you if a restart is required.

    Comment


    • #3


      When the putdocx command uses Stata’s built-in Java engine to create word doc, the java process runs out of heap space. Due to this action, you may face the error "java.lang.OutOfMemoryError: Java heap space". Even with 10,000 observations, certain tables can trigger high memory usage, particularly in cases where you are exporting many variables or long variable names. If you only focus on increasing Stata’s data memory, this will not help you with fixing this issue. It's mainly because, you can see the limitation is on the Java side, not on Stata's main memory.

      You can take a common measure, that is, you can see to reduce the size or complexity of the table you are exporting. You can first try to export fewer variables at a time, shorten variable names.

      You can also clear any unused objects in Stata using clear, drop, or compress, but this will only help if the data itself is consuming memory, not the Java engine.If the issue persists, restarting Stata usually resets the Java heap and allows the export to run again.


      If any updates are missing, you can give priority to upgrading to the latest version. In some cases, updating Stata to a newer version or applying the latest patches resolves Java heap issues because Stata improved memory handling for putdocx in later builds.

      To learn more interesting details about the OutOfMemoryError: Java heap space error, You can check out this blog How to Solve OutOfMemoryError: Java heap space. This will give you more insights about this Java Heap Space error.

      Comment

      Working...
      X