Нужно найти все компоненты связности в которых больше(или равно) четырех вершин. Игра под андроид, сборщик мусора вызывается раз в 3-4 секунды. Если убрать использование графа то ~ раз в минуту. Подскажите как правильно сделать?
class Graph {
    int  NOT_VISIT = 0;
    int      VISIT = 1;
    int LAST_VISIT = 2;
    private class GraphNode {
        ArrayList<Integer> link = new ArrayList<Integer>();
        int type = 0;
    }
    ArrayList<GraphNode> nodes = new ArrayList<GraphNode>();
    ArrayList<Integer> removes = new ArrayList<Integer>();
    int MAX_COUNT = 4;
    public void createGraph(int n){
        removes.clear();
        nodes.clear();
        for(int i = 0; i < n; i++){
            nodes.add(new GraphNode());
        }
    }
    public void addEdge(int a, int b){
        nodes.get(a).link.add(b);
        nodes.get(b).link.add(a);
    }
    public void bfs(int startNode){
        int count = 1;
        Queue<GraphNode> queue = new LinkedList<GraphNode>();
        queue.add(nodes.get(startNode));
        nodes.get(startNode).type = VISIT;
        while(!queue.isEmpty()) {
            GraphNode node = queue.remove();
            for(int i : node.link){
                GraphNode localNode = nodes.get(i);
                if(localNode.type == NOT_VISIT){
                    localNode.type = VISIT;
                    queue.add(localNode);
                    count++;
                }
            }
        }
        if(count >= MAX_COUNT){
            for(int i = 0; i < nodes.size(); i++){
                if(nodes.get(i).type == VISIT){
                    removes.add(i);
                }
            }
        }
        for(GraphNode node : nodes){
            if(node.type == VISIT){
                node.type = LAST_VISIT;
            }
        }
    }
    public ArrayList<Integer> searchBigGroups(){
        for(int i = 0; i < nodes.size(); i++){
            if(nodes.get(i).type == NOT_VISIT){
                bfs(i);
            }
        }
        Collections.sort(removes, Collections.reverseOrder());
        return removes;
    }
}
UPD собственно вызов происходит так
graphBall.createGraph(pBalls.size());
for (Contact contact : world.getContactList()) {
    if (contact.isTouching()) {
        if (contact.getFixtureA().getShape() instanceof CircleShape &&
                contact.getFixtureB().getShape() instanceof CircleShape) {
            if (contact.getFixtureA().getBody().getUserData() != null &&
                    contact.getFixtureB().getBody().getUserData() != null) {
                int a = (Integer) contact.getFixtureA().getBody().getUserData();
                int b = (Integer) contact.getFixtureB().getBody().getUserData();
                if (pBalls.get(a).color == pBalls.get(b).color) {
                    //graphBall.addEdge(a, b);
                }
            }
        }
    }
}
ArrayList<Integer> tmp = graphBall.searchBigGroups();
score += tmp.size() * 3;
for (int index : tmp) {
    // Удаляем все найденное 
    world.destroyBody(pBalls.get(index).body);
    pBalls.remove(index);
}



