I have a java application which seems to allocate more and more memory from OS(but the heap size isn't growing at all!) It's an application communicating with a PLC so it needs quite some CPU.
for testing porpuse I have written this program, to be sure the problem isn't in some library:
public static void main(String[] args) {
Random rand= new Random();
if (args[0].equals("auto")) {
for(int i = 0; i< Integer.valueOf(args[2]);i++) {
new Thread(new Runnable() {
@Override
public void run() {
List<byte[]> threaddata = new ArrayList<>();
while(true) {
byte[] arr = new byte[Integer.valueOf(args[3])];
rand.nextBytes(arr);
threaddata.add(arr);
Thread.sleep(Long.valueOf(args[1]));
threaddata.clear();
Thread.sleep(Long.valueOf(args[1]));
}
}
}).start();
}
}
I have started the application like this
java -XX:NativeMemoryTracking=detail -Xmx1G -XX:+UseG1GC -XX:G1PeriodicGCInterval=10000 -XX:G1HeapWastePercent=10 -jar gctest.jar auto 100 3 10000000
this means the application allocates and releases 10MB every 100ms in 3 Threads.
Now I came across Native Memory Tracking
which gives me this output for Internal
- Internal (reserved=367356KB, committed=367356KB)
(malloc=367324KB #3131147)
(mmap: reserved=32KB, committed=32KB)
At start it needed about 15MB
now it neds almost 400MB
I just came across this documentation but it doesn't realy help me at all. Any clue how I could prevent java from allocating more and more memory from OS?
EDIT: The faster I allocate and release memory, the faster the memory in OS is growing