leakyMedia = new LinkedList<Tuple>();
while (true)
{
IMediaData media = null;
IBuffer buffer = null;
AtomicReference<JNIReference> reference
= new AtomicReference<JNIReference>(null);
try {
media = allocator.getMedia();
buffer = media.getData();
if (buffer == null) {
log.debug("Could not get IBuffer");
throw new OutOfMemoryError();
}
ByteBuffer bBuf = buffer.getByteBuffer(0,
media.getSize(), reference);
if (bBuf == null) {
log.debug("Could not get ByteBuffer");
throw new OutOfMemoryError();
}
// some OSes will cheat and not actually commit the
// pages to memory unless you use them; so let's do
// exactly that.
for(int j = 0; i < media.getSize(); i++)
bBuf.put(j, (byte) 0);
Tuple tuple = new Tuple(bBuf, reference.get());
leakyMedia.add(tuple);
assertNotNull(tuple.getBuffer());
assertNotNull(tuple.getReference());
bytesBeforeFailure += media.getSize();
if (bytesBeforeFailure > 4*1024*1024*1024)
{
// this test causes too much swapping on 64 bit machines, so
// if we get this far, just return
mSuccess = true;
return;
}
} finally {
if (media != null)
media.delete();
if (buffer != null)
buffer.delete();
if (i %100 == 0) {
log.trace(
"iteration: {}; allocated {} bytes; pinned: {}; holding: {}",
new Object[]{i,
bytesBeforeFailure,