Created
April 3, 2015 18:57
-
-
Save xoppa/da8f981791ddabe23dfd to your computer and use it in GitHub Desktop.
FlushablePool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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