JNA is making an insane amount of garbage when I'm trying to find a fake process by name.
Here is a screenshot of the allocations (about 100k.sec)
Here is the test case (used 4.3.0 SNAPSHOT of JNA)
import com.sun.jna.Native;
import com.sun.jna.platform.win32.Kernel32;
import com.sun.jna.platform.win32.Tlhelp32;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinNT;
/**
* Created by Jonathan on 8/26/2016.
*/
public class Main {
public static void main(String[] args) {
while (true)
openProcess("doesntexist.exe");
}
private static final WinDef.DWORD DWORD_ZERO = new WinDef.DWORD(0);
private static final Tlhelp32.PROCESSENTRY32 entry = new Tlhelp32.PROCESSENTRY32.ByReference();
private static WinNT.HANDLE openProcess(String processName) {
WinNT.HANDLE snapshot = Kernel32.INSTANCE.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPALL, DWORD_ZERO);
try {
while (Kernel32.INSTANCE.Process32Next(snapshot, entry)) {
String fileName = Native.toString(entry.szExeFile);
if (processName.equals(fileName))
return Kernel32.INSTANCE.OpenProcess(WinNT.PROCESS_ALL_ACCESS, true, entry.th32ProcessID.intValue());
}
} finally {
Kernel32.INSTANCE.CloseHandle(snapshot);
}
return null;
}
}
And finally here is the memory snapshot https://dl.dropboxusercontent.com/u/91292881/ShareX/2016/08/JNA%204.3.0.snapshot