# org.gradle.launcher.daemon.server.DaemonExpirationPeriodicCheck: Daemon will be stopped at the end of the build after running out of JVM memory

- **ID:** `cicd/gradle-daemon-out-of-memory`
- **Domain:** cicd
- **Category:** resource_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

Gradle daemon exceeded its allocated JVM heap memory, causing the daemon to expire and potentially fail the build due to OutOfMemoryError or GC overhead limit.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Gradle 8.2 | active | — | — |
| JDK 17 | active | — | — |
| Gradle 7.6 | active | — | — |

## Workarounds

1. **Increase the Gradle daemon heap in gradle.properties: org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m. Adjust values based on runner memory (e.g., 4GB runner: -Xmx3072m).** (90% success)
   ```
   Increase the Gradle daemon heap in gradle.properties: org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m. Adjust values based on runner memory (e.g., 4GB runner: -Xmx3072m).
   ```
2. **Disable the daemon for memory-constrained CI by passing --no-daemon to Gradle, but this increases build time.** (75% success)
   ```
   Disable the daemon for memory-constrained CI by passing --no-daemon to Gradle, but this increases build time.
   ```

## Dead Ends

- **** — Restarting the daemon without increasing memory will cause the same failure on the next build. (50% fail)
- **** — Setting -Xmx too high on a CI runner with limited RAM can cause the OS to OOM-kill the process. (30% fail)
