Skip to content

Commit 88200f5

Browse files
committed
Added information about memory requirements
1 parent 7e5943a commit 88200f5

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

docs/reference-manual/native-image/BuildOptions.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ GraalVM 25 introduces the `-H:Preserve` option. This lets you instruct the `nati
140140

141141
You can use `-H:Preserve` in the following ways:
142142

143-
* `-H:Preserve=all`: preserves all elements from the JDK and from the classpath
143+
* `-H:Preserve=all`: preserves all elements from the entire JDK and classpath. This creates larger images but ensures all code is included, which can help resolve missing metadata issues.
144144
* `-H:Preserve=module=<module>`: preserves all elements from a given module
145145
* `-H:Preserve=module=ALL-UNNAMED`: preserves all elements from the classpath (provided with `-cp`).
146146
* `-H:Preserve=package=<package>`: preserves all elements from a given package
@@ -151,8 +151,20 @@ You must explicitly configure multi-interface proxy classes, arrays of dimension
151151

152152
If you get errors related to `--initialize-at-build-time`, follow the suggestions in the error messages.
153153

154+
> **Note:** Using `-H:Preserve=all` requires significant memory and will result in much larger native images. Use the `-Os` flag to reduce image size. For more information, see [Optimizations and Performance](OptimizationsAndPerformance.md).
155+
154156
For a practical demonstration, see the [preserve-package demo](https://github.com/graalvm/graalvm-demos/tree/master/native-image/preserve-package).
155157

158+
#### Memory Requirements
159+
160+
Native Image compilation is memory-intensive, particularly when building large projects or when using -`H:Preserve=all` or `--pgo-instrument`.
161+
162+
If you encounter `OutOfMemoryError: Java heap space` you can:
163+
164+
* use the `-Os` flag to reduce image size. For more information, see [Optimizations and Performance](OptimizationsAndPerformance.md)
165+
* use more specific preservation options like `-H:Preserve=package=<package>` instead of `-H:Preserve=all`
166+
* use more RAM by increasing the heap size with `-J-Xmx<n>g` where `<n>` varies based on your machine's available memory and build requirements
167+
156168
## System Properties
157169

158170
You can define system properties at image build time using the `-D<system.property>=<value>` option syntax.

0 commit comments

Comments
 (0)