Skip to content

Instantly share code, notes, and snippets.

@xoppa
Created April 3, 2015 18:57
Show Gist options
  • Save xoppa/da8f981791ddabe23dfd to your computer and use it in GitHub Desktop.
Save xoppa/da8f981791ddabe23dfd to your computer and use it in GitHub Desktop.
FlushablePool
/** Keeps track of the obtained items and frees them on the call to {@link #flush()}. */
public abstract class FlushablePool<T> extends Pool<T> {
protected Array<T> obtained = new Array<T>();
public FlushablePool () {
}
@Override
public T obtain () {
T result = super.obtain();
obtained.add(result);
return result;
}
/** Frees all obtained instances. */
public void flush () {
super.freeAll(obtained);
obtained.clear();
}
@Override
public void free (T object) {
obtained.removeValue(object, true);
super.free(object);
}
@Override
public void freeAll (Array<T> objects) {
obtained.removeAll(objects, true);
super.freeAll(objects);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment