[#2642] CompositeByteBuf.deallocate memory/GC improvement

Motivation:

CompositeByteBuf.deallocate generates unnecessary GC pressure when using the 'foreach' loop, as a 'foreach' loop creates an iterator when looping.

Modification:

Convert 'foreach' loop into regular 'for' loop.

Result:

Less GC pressure (and possibly more throughput) as the 'for' loop does not create an iterator
This commit is contained in:
Brendt Lucas 2014-07-08 18:31:37 +01:00 committed by Norman Maurer
parent 21aa3d8997
commit 5061be1b03

View File

@ -1583,8 +1583,11 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf {
} }
freed = true; freed = true;
for (Component c: components) { int size = components.size();
c.freeIfNecessary(); // We're not using foreach to avoid creating an iterator.
// see https://github.com/netty/netty/issues/2642
for (int i = 0; i < size; i++) {
components.get(i).freeIfNecessary();
} }
if (leak != null) { if (leak != null) {