You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference-manual/native-image/BuildOptions.md
+13-1Lines changed: 13 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -140,7 +140,7 @@ GraalVM 25 introduces the `-H:Preserve` option. This lets you instruct the `nati
140
140
141
141
You can use `-H:Preserve` in the following ways:
142
142
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.
144
144
*`-H:Preserve=module=<module>`: preserves all elements from a given module
145
145
*`-H:Preserve=module=ALL-UNNAMED`: preserves all elements from the classpath (provided with `-cp`).
146
146
*`-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
151
151
152
152
If you get errors related to `--initialize-at-build-time`, follow the suggestions in the error messages.
153
153
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
+
154
156
For a practical demonstration, see the [preserve-package demo](https://github.com/graalvm/graalvm-demos/tree/master/native-image/preserve-package).
155
157
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
+
156
168
## System Properties
157
169
158
170
You can define system properties at image build time using the `-D<system.property>=<value>` option syntax.
0 commit comments