Skip to content

Commit c3a86fa

Browse files
kiszkcloud-fan
authored andcommitted
[SPARK-10399][SPARK-23879][FOLLOWUP][CORE] Free unused off-heap memory in MemoryBlockSuite
## What changes were proposed in this pull request? As viirya pointed out [here](apache#19222 (comment)), this PR explicitly frees unused off-heap memory in `MemoryBlockSuite` ## How was this patch tested? Existing UTs Author: Kazuaki Ishizaki <[email protected]> Closes apache#21117 from kiszk/SPARK-10399-free-offheap.
1 parent c48085a commit c3a86fa

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

common/unsafe/src/test/java/org/apache/spark/unsafe/memory/MemoryBlockSuite.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ private void check(MemoryBlock memory, Object obj, long offset, int length) {
120120
} catch (Exception expected) {
121121
Assert.assertThat(expected.getMessage(), containsString("should not be larger than"));
122122
}
123+
124+
memory.setPageNumber(MemoryBlock.NO_PAGE_NUMBER);
123125
}
124126

125127
@Test
@@ -165,11 +167,13 @@ public void testOffHeapArrayMemoryBlock() {
165167
int length = 56;
166168

167169
check(memory, obj, offset, length);
170+
memoryAllocator.free(memory);
168171

169172
long address = Platform.allocateMemory(112);
170173
memory = new OffHeapMemoryBlock(address, length);
171174
obj = memory.getBaseObject();
172175
offset = memory.getBaseOffset();
173176
check(memory, obj, offset, length);
177+
Platform.freeMemory(address);
174178
}
175179
}

0 commit comments

Comments
 (0)