<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/java-profiling-java-jvm-native-memory-leaks-4vyxtkpyi" -->

---
title: [Java][Profiling] Java/JVM native memory leaks | daily.dev
description: A deep technical walkthrough of diagnosing native (off-heap) memory leaks in Java/JVM applications, covering Native Memory Tracking (NMT) summary and detail...
canonical: https://daily.dev/posts/java-profiling-java-jvm-native-memory-leaks-4vyxtkpyi
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: [Java][Profiling] Java/JVM native memory leaks | daily.dev
og:description: A deep technical walkthrough of diagnosing native (off-heap) memory leaks in Java/JVM applications, covering Native Memory Tracking (NMT) summary and detail...
og:url: https://daily.dev/posts/java-profiling-java-jvm-native-memory-leaks-4vyxtkpyi
og:image: https://api.daily.dev/og/posts/4vYXTKPYi.png
og:image:alt: [Java][Profiling] Java/JVM native memory leaks
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# [Java][Profiling] Java/JVM native memory leaks

**[Krzysztof Ślusarski](https://daily.dev/sources/krzysztofslusarski)** · 13 min read · 0 upvotes · 0 comments

## Summary

A deep technical walkthrough of diagnosing native (off-heap) memory leaks in Java/JVM applications, covering Native Memory Tracking (NMT) summary and detail modes, jcmd baseline/diff usage, interpreting NMT categories (Heap, Class, Thread, Code, Other), and the limitations of NMT when native code allocates memory outside JVM control. It introduces the new nativemem mode in Async-profiler 4.0, which tracks both allocations and frees to pinpoint leaks precisely, contrasting it with older page-faults and mprotect profiling approaches using a demo Spring Boot app with leaking and non-leaking endpoints. It also explains a separate glibc malloc fragmentation gotcha common on Amazon Corretto/Amazon Linux images, recommending jemalloc via LD_PRELOAD as a fix, noting musl libc (Alpine) doesn't exhibit the issue.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://krzysztofslusarski.github.io/2025/03/31/native.html>

## Questions this post answers

### How can I find native memory leaks in a Java application using Async-profiler?

Use the nativemem event mode introduced in Async-profiler 4.0, which tracks both malloc allocations and frees so it can show exactly which allocations were never freed during profiling. Run it with `-e nativemem`, then convert the JFR file with `jfrconv --total --nativemem --leak` to get a flame graph pinpointing the leaking code path, unlike older page-faults or mprotect based profiling which can't distinguish freed from leaked memory.

_Track profiler updates like async-profiler's nativemem mode on daily.dev when chasing native memory leaks._

### Why does my Java process show much higher RSS memory than the heap size I configured with Xmx?

Native memory areas outside the heap - such as thread stacks, metaspace, code cache for JIT output, and direct ByteBuffer allocations - can account for the gap, and Native Memory Tracking (NMT) in summary mode can reveal how much each category consumes. Additionally, native libraries invoked via JNI can allocate memory the JVM never sees, so NMT committed memory can stay flat while RSS/PSS keeps growing.

_Developers debugging JVM memory bloat can compare tools and JVM behavior notes on daily.dev._

### Why does my Java app's RSS keep growing even though there's no actual memory leak, especially on Amazon Corretto images?

This is often glibc malloc memory fragmentation rather than a true leak, commonly seen when running Amazon Corretto on Amazon Linux docker images; heavy multi-threaded allocation of varying-sized direct ByteBuffers can inflate RSS to several times the heap size even though NMT shows normal committed memory. The fix is switching the allocator to jemalloc via `LD_PRELOAD=/usr/lib64/libjemalloc.so`; musl libc (Alpine) does not exhibit this issue.

_Anyone debugging container memory bloat on AWS JVM deployments can find allocator fixes like this on daily.dev._

## Similar posts on daily.dev

- [Thread Safe Native Memory in Java](https://daily.dev/posts/thread-safe-native-memory-in-java-axg0rs2ub) · Foojay.io · 0 upvotes · 0 comments

---

Tags: [#java](https://daily.dev/tags/java), [#jvm](https://daily.dev/tags/jvm)

[View this post on daily.dev](https://daily.dev/posts/java-profiling-java-jvm-native-memory-leaks-4vyxtkpyi)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"[Java][Profiling] Java/JVM native memory leaks","url":"https://daily.dev/posts/java-profiling-java-jvm-native-memory-leaks-4vyxtkpyi","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/java-profiling-java-jvm-native-memory-leaks-4vyxtkpyi"},"datePublished":"2026-09-27T07:26:30.807Z","dateModified":"2026-09-27T07:27:46.935Z","description":"A deep technical walkthrough of diagnosing native (off-heap) memory leaks in Java/JVM applications, covering Native Memory Tracking (NMT) summary and detail...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/4da187e6480ddcbbcf5d4fc2b8dd7118?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/4da187e6480ddcbbcf5d4fc2b8dd7118?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Krzysztof Ślusarski","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Krzysztof Ślusarski","logo":"https://media.daily.dev/image/upload/logos/placeholder.jpg","url":"https://daily.dev/sources/krzysztofslusarski"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/java-profiling-java-jvm-native-memory-leaks-4vyxtkpyi","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"java,jvm","timeRequired":"PT13M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Krzysztof Ślusarski","item":"https://daily.dev/sources/krzysztofslusarski"},{"@type":"ListItem","position":3,"name":"[Java][Profiling] Java/JVM native memory leaks"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/java-profiling-java-jvm-native-memory-leaks-4vyxtkpyi#faq","mainEntity":[{"@type":"Question","name":"How can I find native memory leaks in a Java application using Async-profiler?","acceptedAnswer":{"@type":"Answer","text":"Use the nativemem event mode introduced in Async-profiler 4.0, which tracks both malloc allocations and frees so it can show exactly which allocations were never freed during profiling. Run it with `-e nativemem`, then convert the JFR file with `jfrconv --total --nativemem --leak` to get a flame graph pinpointing the leaking code path, unlike older page-faults or mprotect based profiling which can't distinguish freed from leaked memory. Track profiler updates like async-profiler's nativemem mode on daily.dev when chasing native memory leaks."}},{"@type":"Question","name":"Why does my Java process show much higher RSS memory than the heap size I configured with Xmx?","acceptedAnswer":{"@type":"Answer","text":"Native memory areas outside the heap - such as thread stacks, metaspace, code cache for JIT output, and direct ByteBuffer allocations - can account for the gap, and Native Memory Tracking (NMT) in summary mode can reveal how much each category consumes. Additionally, native libraries invoked via JNI can allocate memory the JVM never sees, so NMT committed memory can stay flat while RSS/PSS keeps growing. Developers debugging JVM memory bloat can compare tools and JVM behavior notes on daily.dev."}},{"@type":"Question","name":"Why does my Java app's RSS keep growing even though there's no actual memory leak, especially on Amazon Corretto images?","acceptedAnswer":{"@type":"Answer","text":"This is often glibc malloc memory fragmentation rather than a true leak, commonly seen when running Amazon Corretto on Amazon Linux docker images; heavy multi-threaded allocation of varying-sized direct ByteBuffers can inflate RSS to several times the heap size even though NMT shows normal committed memory. The fix is switching the allocator to jemalloc via `LD_PRELOAD=/usr/lib64/libjemalloc.so`; musl libc (Alpine) does not exhibit this issue. Anyone debugging container memory bloat on AWS JVM deployments can find allocator fixes like this on daily.dev."}}]}
```

