Memory Management for ODS Graphics

ODS Graphics uses Java technology to produce its graphs. Most of the time this fact is transparent to you because the required Java Runtime Environment (JRE) and Jar files are included with SAS software installation and the Java environment is automatically started and stopped for you. When Java is started, it allocates a fixed amount of memory that can grow up to the value set for the -Xmx suboption in the JREOPTIONS option (discussed in a moment). This memory is independent of the memory limit that SAS sets for the SAS session with its MEMSIZE= option.
Normally, the memory limit for Java is sufficient for most ODS Graphics applications. However, some tasks are very memory intensive and might exhaust all available Java memory, resulting in an OutOfMemoryError condition. You might encounter Java memory limitations when
  • the product of the output size and the DPI setting results in very large output
  • a classification panel has a very large number of classifier crossings
  • a scatterplot matrix has a large number of variables
  • creating 3D plots and 2D contours, which are memory intensive to generate
  • a plot has a very large number of marker labels
  • a plot uses many character variables or has a large number of GROUP values
  • using the SG Editor to edit a graph with a large amount of data.
If you encounter a Java OutOfMemoryError, you can try executing your program again by restarting SAS and specifying a larger amount of memory for Java at SAS invocation.
To determine what the current Java memory settings are, you can submit a PROC OPTIONS statement that will show the value of the JREOPTIONS option:
proc options option=jreoptions;
run;
After you submit this procedure code, a list of JREOPTIONS settings is displayed in the SAS log. The JREOPTIONS option has many suboptions that configure the SAS Java environment. Many of the suboptions are installation and host specific and should not be modified, especially the ones that provide installed file locations. For managing memory, look for the -Xms and -Xmx suboptions:
-Xms
Use this option to set the minimum Java memory (heap) size, in bytes. Set this value to a multiple of 1024 greater than 1MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default is 2MB. Examples:
-Xms6291456
-Xms6144k
-Xms6m
-Xmx
Use this option to set the maximum size, in bytes, of the memory allocation pool. Set this value to a multiple of 1024 greater than 2MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default is 64MB. Examples:
-Xmx83886080
-Xmx81920k
-Xmx80m
As a general rule, you should set the minimum heap size (-Xms) equal to the maximum heap size (-Xmx) to minimize garbage collections.
Typically, SAS sets both -Xms and -Xmx to be about 1/4 of the total available memory or a maximum of 128M. However, you can set a more aggressive maximum memory (heap) size, but it should never be more than 1/2 of physical memory.
You should be aware of the maximum amount of physical memory your computer has available. Let us assume that doubling the Java memory allocation is feasible. So when you start SAS from a system prompt, you can add the following option:
-jreoptions (-Xmx256m -Xms256m)
Aternatively, you might need to specify the setting in quotation marks:
-jreoptions '(-Xmx256m -Xms256m)'
The exact syntax varies for specifying Java options, depending on your operating system, and the amount of memory that you can allocate varies from system to system. The set of JRE options must be enclosed in parentheses. If you specify multiple JREOPTIONS system options, SAS appends JRE options to JRE options that are currently defined. Incorrect JRE options are ignored.
If you choose to create a custom configuration file, you would simply replace the existing -Xms and -Xmx suboption values in the JREOPTIONS=(all Java options) portion of the configuration file.
For more information, see the SAS Companion for your operating system.