Frees a segment to be reused. Called by the segment-gc service.
356116
public void freeSegment(SegmentKelp segment)
    throws IOException
  {
    // System.out.println("FREE: " + segment);
    SegmentMeta segmentMeta = findSegmentMeta(segment.length());
    
    segmentMeta.remove(segment);
    
    segment.close();
    
    segmentMeta.addFree(segment.extent());
    
    // System.out.println("  FREE: " + segmentMeta.getFreeCount() + " " + segment.getLength());
  }
459893
public void cleanup(boolean reuse, boolean wasInsert)
    {
        if(currentImage != null)
        {
            performImageCleanup(currentImage, reuse);
        }
        if(beforeImage != null)
        {
            // we always free all resources of the old image
            performImageCleanup(beforeImage, false);
        }
        if(reuse)
        {
            refreshObjectImage(wasInsert);
        }
        else
        {
            myObj = null;
        }
    }
157829
void recycleSegment(final File file)
    {
        if (isCapExceeded()
            || CommitLogDescriptor.fromFileName(file.getName()).getMessagingVersion() != MessagingService.current_version)
        {
            // (don't decrease managed size, since this was never a "live" segment)
            logger.debug("(Unopened) segment {} is no longer needed and will be deleted now", file);
            FileUtils.deleteWithConfirm(file);
            return;
        }

        logger.debug("Recycling {}", file);
        // this wasn't previously a live segment, so add it to the managed size when we make it live
        size.addAndGet(DatabaseDescriptor.getCommitLogSegmentSize());
        segmentManagementTasks.add(new Callable<CommitLogSegment>()
        {
            public CommitLogSegment call()
            {
                return new CommitLogSegment(file.getPath());
            }
        });
    }
689774
public void free()
    {
        if (m_messageReceiver != null)
            m_messageReceiver.removeMessageFilter(this, false); // Remove from this and don't free again
        m_messageReceiver = null;
        
        while (this.getMessageListener(0) != null)
        {
            JMessageListener listener = this.getMessageListener(0);
            this.removeFilterMessageListener(listener);
        }
        if (m_vListenerList != null)
            m_vListenerList.clear();
        m_vListenerList = null;
        
        super.free();
        m_intID = null;
    }
1367898
public void free()
    {
        this.freeFiltersWithListener(null);
        if (m_mapFilters.keySet().size() != 0)
            Util.getLogger().warning("Error BaseMessageReceiver.free");   // Shouldn't be any left
        m_mapFilters = null;
        m_intNext = null;
        m_receiver = null;
    }
1223221
synchronized void removeSegment(JournalSegment segment) {
    segments.remove(segment.index());
    segment.close();
    segment.delete();
    resetCurrentSegment();
  }
681551
public void free()
    {
        // Remove all the objects if this is the primary key
        if (this.getPTable().getPKeyArea(Constants.MAIN_KEY_AREA) == this)
        {
            for (int i = m_VectorObjects.size() - 1 ; i >= 0 ;i--)
            {
                BaseBuffer buffer = (BaseBuffer)m_VectorObjects.elementAt(i);
                buffer.free();
            }
        }
        m_VectorObjects.removeAllElements();
        m_VectorObjects = null;

        super.free();
    }
407701
public void resetUnsafe()
    {
        logger.debug("Closing and clearing existing commit log segments...");

        while (!segmentManagementTasks.isEmpty())
            Thread.yield();

        for (CommitLogSegment segment : activeSegments)
            segment.close();
        activeSegments.clear();

        for (CommitLogSegment segment : availableSegments)
            segment.close();
        availableSegments.clear();

        allocatingFrom = null;
    }
1077694
public void free()
    {
        this.stopThisThread();      // This needs to be called first (even though super.free() calls it).
        super.free();               // Free all the filters next (This is also tell the remotesessions to clean up).
        if (m_receiveQueue != null)
        {
            try {
                m_receiveQueue.freeRemoteSession();
            } catch (RemoteException ex)    {
                ex.printStackTrace();
            }
        }
        m_receiveQueue = null;
    }
1284692
public void releaseAll(Object owner) {
		if (owner == null) {
			return;
		}

		// -------------------- BEGIN CRITICAL SECTION -------------------
		synchronized (lock) {
			if (isShutDown) {
				throw new IllegalStateException("Memory manager has been shut down.");
			}

			// get all segments
			final Set<MemorySegment> segments = allocatedSegments.remove(owner);

			// all segments may have been freed previously individually
			if (segments == null || segments.isEmpty()) {
				return;
			}

			// free each segment
			if (isPreAllocated) {
				for (MemorySegment seg : segments) {
					memoryPool.returnSegmentToPool(seg);
				}
			}
			else {
				for (MemorySegment seg : segments) {
					seg.free();
				}
				numNonAllocatedPages += segments.size();
			}

			segments.clear();
		}
		// -------------------- END CRITICAL SECTION -------------------
	}
569908
private void clean(int from, int to) {
        for (int i = from; i < to; i++) {
            ByteBuffer bb = segments.get(i);
            cleanMappedByteBuffer(bb);
            segments.set(i, null);
        }
    }
707369
public void free()
    {
        m_record.removeKeyArea(this);
        m_record = null;

        m_vKeyFieldList.removeAllElements();
        m_vKeyFieldList = null;
        m_strKeyName = null;            // Key Name
    }
539278
def removeSegment(self, segment, preserveCurve=False):
        
        if not isinstance(segment, int):
            segment = self.segments.index(segment)
        segment = normalizers.normalizeIndex(segment)
        if segment >= self._len__segments():
            raise ValueError("No segment located at index %d." % segment)
        preserveCurve = normalizers.normalizeBoolean(preserveCurve)
        self._removeSegment(segment, preserveCurve)
720593
public void free()
    {
    	if (m_recordOwnerCollection != null)
    		m_recordOwnerCollection.free();
    	m_recordOwnerCollection = null;
        if (m_messageFilterList != null)
            m_messageFilterList.free();
        m_messageFilterList = null;
        // Close all records associated with this SessionObject
        if (m_vRecordList != null)
            m_vRecordList.free(this); // Free the records that belong to me
        m_vRecordList = null;

        if (m_databaseCollection != null)
            m_databaseCollection.free();
        m_databaseCollection = null;

        if (m_taskParent != null)
        	m_taskParent.removeRecordOwner(this);
        m_taskParent = null;
    }
994370
protected void cancelTransfers(IntSet removedSegments) {
      synchronized (transferMapsLock) {
         List<Integer> segmentsToCancel = new ArrayList<>(removedSegments);
         while (!segmentsToCancel.isEmpty()) {
            int segmentId = segmentsToCancel.remove(0);
            List<InboundTransferTask> inboundTransfers = transfersBySegment.get(segmentId);
            if (inboundTransfers != null) { // we need to check the transfer was not already completed
               for (InboundTransferTask inboundTransfer : inboundTransfers) {
                  IntSet cancelledSegments = IntSets.mutableCopyFrom(removedSegments);
                  cancelledSegments.retainAll(inboundTransfer.getSegments());
                  segmentsToCancel.removeAll(cancelledSegments);
                  transfersBySegment.keySet().removeAll(cancelledSegments);
                  //this will also remove it from transfersBySource if the entire task gets cancelled
                  inboundTransfer.cancelSegments(cancelledSegments);
                  if (inboundTransfer.isCancelled()) {
                     removeTransfer(inboundTransfer);
                  }
               }
            }
         }
      }
   }
231397
private StorageLocation loadSegmentWithRetry(DataSegment segment, String storageDirStr) throws SegmentLoadingException
  {
    for (StorageLocation loc : locations) {
      if (loc.canHandle(segment)) {
        File storageDir = new File(loc.getPath(), storageDirStr);

        try {
          loadInLocationWithStartMarker(segment, storageDir);
          return loc;
        }
        catch (SegmentLoadingException e) {
          log.makeAlert(
              e,
              "Failed to load segment in current location %s, try next location if any",
              loc.getPath().getAbsolutePath()
          )
             .addData("location", loc.getPath().getAbsolutePath())
             .emit();

          cleanupCacheFiles(loc.getPath(), storageDir);
        }
      }
    }
    throw new SegmentLoadingException("Failed to load segment %s in all locations.", segment.getId());
  }
725917
public void clear() {
        // Clearing all of the links between nodes is "unnecessary", but:
        // - helps a generational GC if the discarded nodes inhabit
        //   more than one generation
        // - is sure to free memory even if there is a reachable Iterator
        for (Node<E> x = first; x != null; ) {
            Node<E> next = x.next;
            x.item = null;
            x.next = null;
            x.prev = null;
            x = next;
        }
        first = last = null;
        size = 0;
        modCount++;
    }