diff --git a/community/io/src/main/java/org/neo4j/io/pagecache/impl/muninn/MuninnPageCursor.java b/community/io/src/main/java/org/neo4j/io/pagecache/impl/muninn/MuninnPageCursor.java index 14a48240d3820..6191500958ca8 100644 --- a/community/io/src/main/java/org/neo4j/io/pagecache/impl/muninn/MuninnPageCursor.java +++ b/community/io/src/main/java/org/neo4j/io/pagecache/impl/muninn/MuninnPageCursor.java @@ -53,7 +53,7 @@ abstract class MuninnPageCursor implements PageCursor protected int pf_flags; protected long currentPageId; protected long nextPageId; - protected PageCursor linkedCursor; + protected MuninnPageCursor linkedCursor; private long pointer; private int pageSize; private int filePageSize; @@ -109,12 +109,24 @@ public final boolean next( long pageId ) throws IOException @Override public final void close() { - unpinCurrentPage(); - releaseCursor(); - closeLinkedCursorIfAny(); - // We null out the pagedFile field to allow it and its (potentially big) translation table to be garbage - // collected when the file is unmapped, since the cursors can stick around in thread local caches, etc. - pagedFile = null; + MuninnPageCursor cursor = this; + do + { + cursor.unpinCurrentPage(); + cursor.releaseCursor(); + // We null out the pagedFile field to allow it and its (potentially big) translation table to be garbage + // collected when the file is unmapped, since the cursors can stick around in thread local caches, etc. + cursor.pagedFile = null; + + } + while ( (cursor = cursor.getAndClearLinkedCursor()) != null ); + } + + private MuninnPageCursor getAndClearLinkedCursor() + { + MuninnPageCursor cursor = linkedCursor; + linkedCursor = null; + return cursor; } private void closeLinkedCursorIfAny() @@ -130,7 +142,7 @@ private void closeLinkedCursorIfAny() public PageCursor openLinkedCursor( long pageId ) { closeLinkedCursorIfAny(); - linkedCursor = pagedFile.io( pageId, pf_flags ); + linkedCursor = (MuninnPageCursor) pagedFile.io( pageId, pf_flags ); return linkedCursor; }