java
11 minJVM Memory Errors: Diagnose Heap Exhaustion, StackOverflow, and Leaks
Separate heap pressure from thread-stack failure, collect the right evidence, and fix the retention path rather than masking symptoms.
Loading page...
java
11 minSeparate heap pressure from thread-stack failure, collect the right evidence, and fix the retention path rather than masking symptoms.
Q&A
Q&AHeap or native-resource exhaustion differs from exhausting one thread call stack.
OutOfMemoryError identifies an allocation resource that could not be satisfied, such as Java heap, metaspace, direct buffers, or native threads. StackOverflowError usually indicates an excessively deep call chain or runaway recursion in one thread. Read the exact message, capture JVM and container metrics, and use a heap dump or thread stack evidence before changing memory flags.
Q&A
Q&ACompare traced allocation snapshots to identify Python allocation sites, then verify process-level memory too.
Start tracemalloc before the workload, take snapshots at comparable points, and compare line-level allocation differences. It tracks Python-managed allocations, not every native allocation from extensions or system libraries. Correlate it with RSS and object-retention behavior; growing allocation totals do not alone prove a leak if objects are later freed.
Q&A
Q&AHashMap stores entries in buckets, resolves collisions with linked lists or trees, and resizes when load crosses a threshold.
HashMap uses an array of buckets and computes an index from the hash of the key. Each bucket may hold one or more entries. When collisions happen, Java stores entries in a linked list and later in a tree when the bucket grows large enough. The table resizes when the load factor is exceeded so the map keeps operations efficient. The key idea is balancing fast lookup with controlled memory use.
python
14 minDebug memory outside Python objects, choose ASGI worker boundaries, and find silent hangs in background consumers.
Q&A
Q&AConcurrentHashMap is designed for concurrent reads and writes without locking the entire map.
Modern Java ConcurrentHashMap does not use the fixed lock segments from older implementations. It uses non-blocking reads and coordinates updates with CAS and synchronization at individual bins when needed. This allows unrelated keys to make progress concurrently. It protects map operations, not a multi-key transaction or mutable values stored inside it.
Q&A
Q&ANative stack memory, scheduling overhead, context switching, and file descriptors can be exhausted.
Each platform thread consumes native resources, including stack reservation, and excessive runnable threads add scheduling and context-switching overhead. The service may hit native-thread creation errors or degrade before that point. Bound executors, measure queue depth and task latency, and apply backpressure rather than creating one thread per unbounded unit of work.
java
7 minUnderstand how modern ConcurrentHashMap combines volatile reads, CAS, and narrow bin-level locking, and where its guarantees stop.