diff --git a/java/debugger/impl/src/com/intellij/debugger/jdi/VirtualMachineProxyImpl.java b/java/debugger/impl/src/com/intellij/debugger/jdi/VirtualMachineProxyImpl.java index aab8a453df82..5b80d5514371 100644 --- a/java/debugger/impl/src/com/intellij/debugger/jdi/VirtualMachineProxyImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/jdi/VirtualMachineProxyImpl.java @@ -19,6 +19,7 @@ */ package com.intellij.debugger.jdi; +import com.intellij.Patches; import com.intellij.debugger.engine.DebugProcess; import com.intellij.debugger.engine.DebugProcessImpl; import com.intellij.debugger.engine.DebuggerManagerThreadImpl; @@ -333,12 +334,14 @@ public class VirtualMachineProxyImpl implements JdiTimer, VirtualMachineProxy { LOG.info(e); } - // Memory leak workaround, see IDEA-163334 - TargetVM target = ReflectionUtil.getField(myVirtualMachine.getClass(), myVirtualMachine, TargetVM.class, "target"); - if (target != null) { - Thread controller = ReflectionUtil.getField(target.getClass(), target, Thread.class, "eventController"); - if (controller != null) { - controller.stop(); + if (Patches.JDK_BUG_EVENT_CONTROLLER_LEAK) { + // Memory leak workaround, see IDEA-163334 + TargetVM target = ReflectionUtil.getField(myVirtualMachine.getClass(), myVirtualMachine, TargetVM.class, "target"); + if (target != null) { + Thread controller = ReflectionUtil.getField(target.getClass(), target, Thread.class, "eventController"); + if (controller != null) { + controller.stop(); + } } } } diff --git a/platform/util/src/com/intellij/Patches.java b/platform/util/src/com/intellij/Patches.java index 41dd4f41ba27..6c91541c0fb7 100644 --- a/platform/util/src/com/intellij/Patches.java +++ b/platform/util/src/com/intellij/Patches.java @@ -77,6 +77,11 @@ public class Patches { */ public static final boolean JDK_BUG_ID_8042123 = !SystemInfo.isJavaVersionAtLeast("1.8.0_40"); + /** + * Enable workaround for jdk bug with leaking TargetVM.EventController, see IDEA-163334 + */ + public static final boolean JDK_BUG_EVENT_CONTROLLER_LEAK = true; + /** * JDK on Mac detects font style for system fonts based only on their name (PostScript name). * This doesn't work for some fonts which don't use recognizable style suffixes in their names.