protected byte[] allocateByteArray(int size, boolean returnNullIfNoMemory) {
        boolean canAlloc = true;
        if (memoryManager != null && size >= 512 * 1024)
            canAlloc = memoryManager.checkMemory(size);
        if (returnNullIfNoMemory && !canAlloc)
            return null;
        return new byte[size];
    }