Understanding Memory Leaks, Memory Overflow, Young GC STW, Major vs Full GC, and Direct Memory in Java
This article explains the difference between memory leaks and overflow, whether young GC triggers stop‑the‑world pauses, distinguishes major GC from full GC, and describes Java's direct memory usage, providing clear insights into Java memory management and performance considerations.
(1) Difference between memory leak and memory overflow: A memory leak occurs when objects that are no longer used cannot be reclaimed promptly, continuously occupying memory and causing waste. Leaks often lead to overflow, but overflow does not necessarily stem from a leak.
(2) Does Young GC involve stop‑the‑world (STW) pauses? All garbage collectors issue a stop‑the‑world pause; the duration varies. Serial, Parallel Scavenge, and ParNew pause user threads regardless of being serial or parallel. CMS and G1 avoid pausing during concurrent marking, but they still pause at other phases, resulting in shorter STW times.
(3) Difference between Major GC and Full GC: In many references, Major GC is synonymous with Full GC, and monitoring tools often show only Minor GC and Full GC. A Full GC reclaims memory across the young generation, old generation, metaspace, and off‑heap memory. Triggers include promotion of large objects to the old generation exceeding its free space, old‑generation usage surpassing a threshold, metaspace exhaustion (e.g., permanent generation in JDK 1.7), or an explicit call to System.gc().
(4) What is direct memory? Java NIO allows programs to allocate direct memory outside the Java heap, directly from the operating system. Access to direct memory is typically faster than heap memory, making it attractive for high‑frequency read/write scenarios. Although its size is not limited by the -Xmx heap setting, the total of heap and direct memory is still constrained by the physical memory available on the host OS.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
