Courseiva
Question 1,122 of 724
Development with AWS ServiceshardMultiple ChoiceObjective-mapped

DVA-C02 Development with AWS Services Practice Question

A developer is using AWS CodeBuild to build a Java application. The build fails with 'OutOfMemoryError: Java heap space'. How can the developer fix this without changing the source code?

⚠ Common exam trap

Many candidates confuse the JVM's -Xmx flag (a code-level fix) with the infrastructure-level memory allocation controlled by the CodeBuild compute type, and incorrectly assume a 'memory parameter' exists as a separate setting in CodeBuild.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Increase the compute type of the build project

AWS CodeBuild allows you to increase the compute type (e.g., from BUILD_GENERAL1_SMALL to BUILD_GENERAL1_MEDIUM or LARGE), which provides more memory and CPU resources. This directly addresses the 'OutOfMemoryError: Java heap space' by giving the JVM more physical memory to work with, without requiring any source code changes.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Add -Xmx1024m to the buildspec commands

    Why it's wrong here

    Directly adding -Xmx1024m to buildspec commands is generally ineffective for resolving heap space errors in a Java application's build process. While -Xmx sets the maximum heap size for a Java Virtual Machine (JVM), this parameter needs to be passed to the specific `java` command or the build tool's JVM (e.g., via MAVEN_OPTS for Maven or GRADLE_OPTS for Gradle) that is executing the build. Simply placing it as a standalone command or without proper context in buildspec will not automatically apply it to the correct JVM process, thus failing to increase the allocated memory for the build.

  • Change the build image to a smaller one

    Why it's wrong here

    Changing the build image to a smaller one would exacerbate a heap space error rather than resolve it. While a smaller image might reduce download times and disk footprint, it typically does not increase the available memory for the CodeBuild container. In fact, smaller images are often associated with or used on lower-resource compute types, which inherently provide less CPU and memory. A heap space error indicates a need for *more* memory, making any reduction in available resources counterproductive.

  • Set the memory parameter in the build project

    Why it's wrong here

    CodeBuild does not offer a standalone, configurable "memory parameter" that can be set independently for a build project. Memory allocation in CodeBuild is intrinsically tied to the chosen compute type. Each compute type (e.g., BUILD_GENERAL1_SMALL, MEDIUM, LARGE) bundles a specific amount of CPU and memory resources. Therefore, attempting to configure memory separately is not possible within the CodeBuild project settings, as it is not an exposed parameter.

  • Increase the compute type of the build project

    Why this is correct

    Increasing the compute type of the CodeBuild project is the correct solution for a Java application encountering a heap space error. CodeBuild compute types, such as BUILD_GENERAL1_MEDIUM or BUILD_GENERAL1_LARGE, provide progressively more CPU and, crucially, more memory to the build environment. By selecting a higher compute type, the underlying container running the build will have access to a larger pool of RAM, directly addressing the "out of heap space" issue by allowing the Java Virtual Machine to allocate more memory for the build process.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Last reviewed: Jul 4, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

This DVA-C02 practice question is part of Courseiva's free Amazon Web Services certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DVA-C02 exam.