The majority of memory issues can be reproduced in any environment without significant effort.It is often easier to troubleshoot memory issues on your local machine because you’ll have access to more tools and won’t have to be as concerned with side effects that monitoring tools may cause.However, Heroku’s JVM languages support provides tools that simplify this.If your app is experiencing high levels of native memory usage (i.e.the difference between Total RSS and JVM Heap), then you may need to configure your application to print Native Memory Tracking information when it shuts down.To do so, set the following configuration variable: Sometimes, a single heap dump is not enough and multiple heap dumps are required in order to identify trends in heap usage and memory leaks.You’ll see R14 errors in your application logs when this paging starts to happen.
The stack stores primitive local variables and object references along with the call stack (method invocations) itself.
It is also possible to generate a thread dump from application code.
This is useful when trying to generate a dump as the process exits.
Tuning the memory use of your application requires understanding both how Java uses memory and how you can gain visibility into your application’s memory use. The primary, but not singular, use of memory is in the heap.
Outside of the heap, memory is also consumed by Metaspace and the stack.
The stack is cleaned up as stack frames move out of context so there is no GC performed here.