Index: PriorityQueue.java =================================================================== --- PriorityQueue.java (revision 413208) +++ PriorityQueue.java (working copy) @@ -23,6 +23,11 @@ private Object[] heap; private int size; private int maxSize; + + /** + * With current queue implementation would not want to allocate an array of more than 1M objects. + */ + public static final int MAX_QUEUE_SIZE = 1000000; /** Determines the ordering of objects in this priority queue. Subclasses must define this one method. */ @@ -31,6 +36,7 @@ /** Subclass constructors must call this. */ protected final void initialize(int maxSize) { size = 0; + maxSize = (maxSize>MAX_QUEUE_SIZE ? MAX_QUEUE_SIZE : maxSize); //avoid allocating a too large heap array int heapSize = maxSize + 1; heap = new Object[heapSize]; this.maxSize = maxSize;