javamemory-leaksjvmjemalloc

Jemalloc with java on Mac


trying to load jemalloc for java program to find native memory leak ,but unable to get it worked. Steps performed so far

versions : Mac OS 14.3 , JDK 11 , jemalloc - 5.3.0

1.Installed jemalloc via brew

2.set env variable LD_PRELOAD= {path_to_lib}/libjemalloc.2.dylib (tried libjemalloc.dylib also )

3.and this also MALLOC_CONF=prof:true,lg_prof_interval:10,lg_prof_sample:17,prof_prefix:my_path

and I am expecting at least some logs which shows me if this is working but neither seeing logs nor seeing jeprof.**.heap

I even ran normal program with LD_PRELOAD= {path_to_lib}/libjemalloc.2.dylib MALLOC_CONF=prof:true,lg_prof_interval:10,lg_prof_sample:17,prof_prefix:my_path java test.jar

my java program is simply leaking native memory via Bytebuffer.allocateDirect() and want to check this via jemalloc.

Questions :

  1. jemalloc works on Mac OS? Do I need to install and build myself instead of brew ?
  2. Any other config is missing ?

Solution

  • LD_PRELOAD is Linux-specific.

    On macOS, there is a different mechanism for preloading shared libraries. Look for DYLD_INSERT_LIBRARIES. Note this may not work with SIP (System Integrity Protection) enabled.