Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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