Github user JoshRosen commented on a diff in the pull request:
https://github.com/apache/spark/pull/9260#discussion_r42928573
--- Diff:
core/src/main/scala/org/apache/spark/util/collection/ExternalAppendOnlyMap.scala
---
@@ -214,13 +215,18 @@ class ExternalAppendOnlyMap[K, V, C](
spilledMaps.append(new DiskMapIterator(file, blockId, batchSizes))
}
+ private def freeCurrentMap(): Unit = {
+ currentMap = null // So that the memory can be garbage-collected
+ releaseMemoryForThisThread()
+ }
+
/**
* Return an iterator that merges the in-memory map with the spilled
maps.
* If no spill has occurred, simply return the in-memory map's iterator.
*/
override def iterator: Iterator[(K, C)] = {
if (spilledMaps.isEmpty) {
- currentMap.iterator
+ CompletionIterator[(K, C), Iterator[(K, C)]](currentMap.iterator,
freeCurrentMap())
--- End diff --
I debated whether to push this burden to callers rather than using a
`CompletionIterator` here until I noticed that `ExternalIterator()` ends up
calling `currentMap.destructiveSortedIterator()`, so (implicitly) this method
already had the limitation that it could only be called once.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]