public long freeMemory() {
   long memoryFreed = 0;
   for (MemoryBlock block : allocatedPages) {
     memoryManager.freePage(block);
     shuffleMemoryManager.release(block.size());
     memoryFreed += block.size();
   }
   allocatedPages.clear();
   currentPage = null;
   currentPagePosition = -1;
   freeSpaceInCurrentPage = 0;
   return memoryFreed;
 }
示例#2
0
 /**
  * Clean up all allocated memory and pages. Returns the number of bytes freed. A non-zero return
  * value can be used to detect memory leaks.
  */
 public long cleanUpAllAllocatedMemory() {
   long freedBytes = 0;
   for (MemoryBlock page : pageTable) {
     if (page != null) {
       freedBytes += page.size();
       freePage(page);
     }
   }
   final Iterator<MemoryBlock> iter = allocatedNonPageMemory.iterator();
   while (iter.hasNext()) {
     final MemoryBlock memory = iter.next();
     freedBytes += memory.size();
     // We don't call free() here because that calls Set.remove, which would lead to a
     // ConcurrentModificationException here.
     executorMemoryManager.free(memory);
     iter.remove();
   }
   return freedBytes;
 }