Frees a segment to be reused. Called by the segment-gc service.
547835
public void freeSegment(SegmentKelp segment)
    throws IOException
  {
    freeTableSegmentLength(segment.length());
    
    // System.out.println("FREE: " + _tableLength + " " + segment.getLength() + " " + segment);
    
    _segmentService.freeSegment(segment);
  }
515300
public void free()
    {
        Record record = null;
        if (this.getMessageSource() instanceof Record)
            record = (Record)this.getMessageSource();
        
        super.free();
        
        if (record != null)
        {
            BaseSyncRecordMessageFilterHandler fileListener = (BaseSyncRecordMessageFilterHandler)record.getListener(BaseSyncRecordMessageFilterHandler.class, false);
            if (fileListener != null)
                if (fileListener.getRecordMessageFilter() == this)
            {   // Always
                    // Note: Removing this fileListener will call free again for this object... shouldn't be a problem, since everything has been zeroed --- may want to fix this later
                record.removeListener(fileListener, true);
            }
        }
    }
1220615
def _removeSegment(self, segment, preserveCurve, **kwargs):
        
        segment = self.segments[segment]
        for point in segment.points:
            self.removePoint(point, preserveCurve)
257159
public synchronized void replaceSegments(Collection<Segment> segments, Segment segment) {
    // Update the segment descriptor and lock the segment.
    segment.descriptor().update(System.currentTimeMillis());
    segment.descriptor().lock();

    // Iterate through old segments and remove them from the segments list.
    for (Segment oldSegment : segments) {
      if (!this.segments.containsKey(oldSegment.index())) {
        throw new IllegalArgumentException("unknown segment at index: " + oldSegment.index());
      }
      this.segments.remove(oldSegment.index());
    }

    // Put the new segment in the segments list.
    this.segments.put(segment.index(), segment);

    resetCurrentSegment();
  }
1229686
public synchronized boolean freeSegment(Segment seg) throws IOException {
        if (seg == null)
            return false;

        int segId = seg.getSegmentId();
        if (segId < _segList.size() && _segList.get(segId) == seg) {
            _segList.set(segId, null);
            seg.close(false);
            
            if(segId == (_segList.size() - 1)) {
                try {
                    // Delete last segment.
                    _segList.remove(segId);
                    
                    File segFile = seg.getSegmentFile();
                    if(segFile.exists()) segFile.delete();
                    
                    File sibFile = getSegmentIndexBufferFile(segId);
                    if(sibFile.exists()) sibFile.delete();
                    
                    _log.info("Segment " + seg.getSegmentId() + " deleted");
                } catch(Exception e) {
                    _log.warn("Segment " + seg.getSegmentId() + " not deleted", e);
                }
            } else {
                if (seg.isRecyclable() && recycle(seg)) {
                    _log.info("Segment " + seg.getSegmentId() + " recycled");
                } else {
                    _log.info("Segment " + seg.getSegmentId() + " freed");
                }
            }
            
            return true;
        }
        
        return false;
    }
732172
@Override
	public List<MemorySegment> dispose() {
		this.freeMemory.addAll(this.sortBuffer);
		this.sortBuffer.clear();
		return this.freeMemory;
	}
576358
public void clear()
    {
        // clear out ref queue. We don't need to expunge entries
        // since gc'ed entries won't get copied.
        emptyReferenceQueue();

        for (int i = 0; i < table.length; i++)
        {
            Entry e = table[i];
            Entry first = null;
            Entry prev = null;
            while (e != null)
            {
                Object candidate = e.get();
                if (candidate != null)
                {
                    Entry dirty = e.makeDirtyAndWeak(queue);
                    if (first == null)
                    {
                        first = dirty;
                    }
                    if (prev != null)
                    {
                        prev.setNext(dirty);
                    }
                    prev = dirty;
                }
                else
                {
                    if (prev != null)
                    {
                        prev.setNext(e.getState().next);
                    }
                    size--;
                }
                e = e.getState().next;
            }
            table[i] = first;
        }

        // Allocation of array may have caused GC, which may have caused
        // additional entries to go stale.  Removing these entries from the
        // reference queue will make them eligible for reclamation.
        expungeStaleEntries();
    }
541363
public void free()
    {
        if (m_receiver != null)
            m_receiver.free();
        m_receiver = null;
        if (m_sender != null)
            m_sender.free();
        m_sender = null;

        if (m_manager != null)
            m_manager.removeMessageQueue(this);

        m_manager = null;
        m_strQueueName = null;
        m_strQueueType = null;
    }
267957
@GuardedBy("readers")
    private void releaseSegmentsIfNeeded() throws ReaderNotInReaderGroupException {
        releaseSealedSegments();
        Segment segment = groupState.findSegmentToReleaseIfRequired();
        if (segment != null) {
            log.info("{} releasing segment {}", this, segment);
            EventSegmentReader reader = readers.stream().filter(r -> r.getSegmentId().equals(segment)).findAny().orElse(null);
            if (reader != null) {
                if (groupState.releaseSegment(segment, reader.getOffset(), getLag())) {
                    readers.remove(reader);
                    reader.close();
                }
            }
        }
    }
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;
    }
431340
public void free()
    {
        if (m_sendQueue != null)
        {
            try {
                m_sendQueue.freeRemoteSession();
            } catch (RemoteException ex)    {
                ex.printStackTrace();
            }
        }
        m_sendQueue = null;
        super.free();
    }
1050867
public void free()
    {
        super.free();
        try
        {
            if (this.getHandle(DBConstants.DATA_SOURCE_HANDLE) != null)
                ((BaseBuffer)this.getHandle(DBConstants.DATA_SOURCE_HANDLE)).free();
        } catch (DBException ex)    {
            // Never
        }
        if (m_pTable != null)
            m_pTable.removePTableOwner(this, true);      // Free or decrement the use count of the physical table
        m_pTable = 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;
    }
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;
    }
74024
public static void bitUnSet(MemorySegment segment, int baseOffset, int index) {
		int offset = baseOffset + ((index & BIT_BYTE_POSITION_MASK) >>> 3);
		byte current = segment.get(offset);
		current &= ~(1 << (index & BIT_BYTE_INDEX_MASK));
		segment.put(offset, current);
	}
166651
protected void deselectSegment(Segment segment) {
    if(segment.isUnpaired()) {
      ArrayList<Segment> remove = new ArrayList<>();
      // remove all object segments associated with unpaired segment from
      // selection list
      for(Entry<Segment, Segment> entry : indirectSelections.entrySet()) {
        if(entry.getValue() == segment) {
          remove.add(entry.getKey());
        }
      }

      for(Segment other : remove) {
        indirectSelections.remove(other);
        deselectSegment(other);
      }
    }
    else {
      // check if deselected object Segment has a unpaired segment highlighted
      Segment unpaired = indirectSelections.get(segment);
      if(unpaired != null) {
        // remove highlight
        deselectSegment(unpaired);
      }
      if(selectedSegments.remove(segment) && segment.getDBIDs() != null) {
        unselectedObjects.addDBIDs(segment.getDBIDs());
      }
    }
  }
837210
@Override
    public void clear() {
        try {
            lockAllSegments();
            for (LinkedHashMapSegment<K, V> seg : segments) {
                seg.clear();
            }
        } finally {
            unlockAllSegments();
        }
    }