[#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 33a810a513
commit ac8ac59148

View File

@ -1599,8 +1599,11 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf {
}
freed = true;
for (Component c: components) {
c.freeIfNecessary();
int size = components.size();
// 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) {