Skip to content

Commit

Permalink
remove leaked counters when they are closed to avoid memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardWarburton committed Jun 4, 2020
1 parent b9014b6 commit 37bde1a
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import org.agrona.concurrent.status.AtomicCounter;
import uk.co.real_logic.artio.dictionary.generation.Exceptions;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class FixCounters implements AutoCloseable
{
Expand Down Expand Up @@ -51,7 +51,7 @@ public int id()
}
}

private final List<Counter> counters = new ArrayList<>();
private final List<Counter> counters = new CopyOnWriteArrayList<>();
private final AtomicCounter failedInboundPublications;
private final AtomicCounter failedOutboundPublications;
private final AtomicCounter failedReplayPublications;
Expand All @@ -60,6 +60,8 @@ public int id()
FixCounters(final Aeron aeron)
{
this.aeron = aeron;
aeron.addUnavailableCounterHandler((countersReader, registrationId, counterId) ->
counters.removeIf(counter -> counter.id() == counterId));
failedInboundPublications = newCounter(FixCountersId.FAILED_INBOUND_TYPE_ID.id(),
"Failed offer to inbound publication");
failedOutboundPublications = newCounter(FixCountersId.FAILED_OUTBOUND_TYPE_ID.id(),
Expand Down

0 comments on commit 37bde1a

Please sign in to comment.