JakeWharton / scalpel

A surgical debugging tool to uncover the layers under your app.
Apache License 2.0
2.77k stars 232 forks source link

Pool or Kill LayeredView #9

Closed JakeWharton closed 10 years ago

JakeWharton commented 10 years ago

It's currently allocating a TON inside of a draw call.

JakeWharton commented 10 years ago

Poor man's pool?

private static abstract class Pool<T> {
  private final Deque<T> pool;

  Pool(int initialSize) {
    pool = new ArrayDeque<T>(initialSize);
    for (int i = 0; i < initialSize; i++) {
      pool.addLast(newObject());
    }
  }

  T obtain() {
    return pool.isEmpty() ? newObject() : pool.removeLast();
  }

  void restore(T instance) {
    pool.addLast(instance);
  }

  protected T newObject();
}
JakeWharton commented 10 years ago

3b770ea89ec28d37d15861b1e5f14294f44fc3aa