diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioEventLoop.java b/transport/src/main/java/io/netty/channel/socket/nio/NioEventLoop.java index e8c643b224..113db6d8b9 100644 --- a/transport/src/main/java/io/netty/channel/socket/nio/NioEventLoop.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/NioEventLoop.java @@ -253,6 +253,9 @@ final class NioEventLoop extends SingleThreadEventLoop { private void processSelectedKeys() { Set selectedKeys = selector.selectedKeys(); + // check if the set is empty and if so just return to not create garbage by + // creating a new Iterator every time even if there is nothing to process. + // See https://github.com/netty/netty/issues/597 if (selectedKeys.isEmpty()) { return; }