가짜 프로세스를 이름으로 찾기 위해 JNA가 쓰레기를 만들어냅니다. 여기 자바 JNA 4.3.0은 프로세스를 찾을 때 쓰레기를 아주 많이 만듭니다.
은 할당 (약 100k.sec) 여기서 은 (JNA의 사용 4.3.0 SNAPSHOT)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;
}
}
마지막 여기 테스트 케이스 인의 스크린 샷이다 메모리 스냅 샷입니다 https://dl.dropboxusercontent.com/u/91292881/ShareX/2016/08/JNA%204.3.0.snapshot
몇 개의 프로세스를 만들고 있습니까? while 루프처럼 보이는 코드를 추적하면 그것들 모두에 대해'Tlhelp32.PROCESSENTRY32' 구조체가 생성됩니다. –
또한 어디서 4.3.0을 얻고 있습니까? 최신 릴리스는 4.2.2입니다. 스냅 샷 빌드입니까? –
예 스냅 샷 빌드입니다. –