shared cleanup from finish & finishKeepConnection
195859
protected void cleanupFromFinish() {
        _response = null;
        _bufferSize = 0;
        _encoding = null;
        // LIBERTY _responseBuffer = null;
        // _outWriterEncoding = null;
        _gotOutputStream = false;
        _gotWriter = false;
        this._pwriter = null;
    }
186627
private void cleanup() {
        long traceId = LoggerHelpers.traceEnterWithContext(log, this.traceObjectId, "cleanup");
        val toRemove = this.processors.values().stream()
                                      .map(this::closeIfNecessary)
                                      .filter(ProcessorCollection::isClosed)
                                      .map(ProcessorCollection::getId)
                                      .collect(Collectors.toList());
        toRemove.forEach(this.processors::remove);
        LoggerHelpers.traceLeave(log, this.traceObjectId, "cleanup", traceId, toRemove.size());
    }
1264205
function cleanup() {
      res.removeListener('finish', sendStats);
      res.removeListener('error', cleanup);
      res.removeListener('close', cleanup);
    }
1146792
def _cleanup_fd(self, fd, close=False):
        
        self._ioloop.remove_handler(fd)
        if fd in self._connections:
            try:
                self._pool_manager.free(self.pid, self._connections[fd])
            except pool.ConnectionNotFoundError:
                pass
            if close:
                self._connections[fd].close()
            del self._connections[fd]
        if fd in self._futures:
            del self._futures[fd]
1232177
synchronized void cleanUp() {

        updateAccessCounts();

        int                          removeCount = size() / 2;
        int accessTarget = getAccessCountCeiling(removeCount, removeCount / 8);
        BaseHashMap.BaseHashIterator it          = new BaseHashIterator();
        int                          savecount   = 0;

        for (; it.hasNext(); ) {
            CachedObject r = (CachedObject) it.next();

            if (it.getAccessCount() <= accessTarget) {
                synchronized (r) {
                    if (!r.isKeepInMemory()) {
                        r.setInMemory(false);

                        if (r.hasChanged()) {
                            rowTable[savecount++] = r;
                        }

                        it.remove();

                        cacheBytesLength -= r.getStorageSize();

                        removeCount--;
                    }
                }
            }
        }

        if (removeCount > 50) {
            it = new BaseHashIterator();

            for (; removeCount >= 0 && it.hasNext(); ) {
                CachedObject r = (CachedObject) it.next();

                if (!r.isKeepInMemory()) {
                    r.setInMemory(false);

                    if (r.hasChanged()) {
                        rowTable[savecount++] = r;
                    }

                    it.remove();

                    cacheBytesLength -= r.getStorageSize();

                    removeCount--;
                }
            }
        }

        super.setAccessCountFloor(accessTarget);
        saveRows(savecount);
    }
276068
def cleanup(self):
        ''''''
        if self.state == ClientState.WAITING_FOR_RESULT:
            # There is an ongoing call to execute()
            # Not sure what to do here
            logger.warn('cleanup() called while state is WAITING_FOR_RESULT: ignoring')
        elif self.state == ClientState.TERMINATING:
            # terminate() has been called but we have not recieved SIGCHLD yet
            # Not sure what to do here
            logger.warn('cleanup() called while state is TERMINATING: ignoring')
        elif self.state in ClientState.TerminatedSet:
            # We have already terminated
            # TODO: should we deal with TERMINATED_ASYNC in some special way?
            logger.debug('cleanup() called while state is TERMINATING: nothing needs to be done')
        else:
            logger.debug('cleanup() called while state is %s: attempting to terminate',
                          self.strstate)
            try:
                self.terminate()
            except ProcessTerminationError as ex:
                # Terminate can throw a ProcessTerminationError if the
                # process terminated at some point between the last
                # execute() and the call to terminate()
                # For now we just ignore this.
                pass
932806
private void internalCleanup()
    {
        if(hasBroker())
        {
            PersistenceBroker broker = getBroker();
            if(log.isDebugEnabled())
            {
                log.debug("Do internal cleanup and close the internal used connection without" +
                        " closing the used broker");
            }
            ConnectionManagerIF cm = broker.serviceConnectionManager();
            if(cm.isInLocalTransaction())
            {
                /*
                arminw:
                in managed environment this call will be ignored because, the JTA transaction
                manager control the connection status. But to make connectionManager happy we
                have to complete the "local tx" of the connectionManager before release the
                connection
                */
                cm.localCommit();
            }
            cm.releaseConnection();
        }
    }
989947
private void cleanup() {
        StatsDataReference ref = null;
        while ((ref = (StatsDataReference) statisticsReferenceQueue.poll()) != null) {
            StatsData oldStats = null;
            StatsData updatedStats = null;
            do {
                oldStats = terminatedThreadStats.get();
                updatedStats = aggregateStats(oldStats, ref.statsData);
            } while (!terminatedThreadStats.compareAndSet(oldStats, updatedStats));
            allReferences.remove(ref);
        }
    }
276334
public boolean cleanupDestination()
  throws 
    SIRollbackException, 
    SIConnectionLostException, 
    SIIncorrectCallException, 
    SIResourceException, 
    SIErrorException   
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "cleanupDestination");
  
    boolean cleanedUp = false;

    //Ensure any cleanup does not occur at the same time the link is being used.
    synchronized(this)
    {
      if (isToBeDeleted())
      {
        // Tidy up the state item streams first
        LocalTransaction siTran =
          txManager.createLocalTransaction(true);          
        removeStateItemStreams((Transaction) siTran); 
        siTran.commit();
      }
    }

    // Now tidy up the rest of the infrastructure    
    cleanedUp = cleanupBaseDestination();
   
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "cleanupDestination", Boolean.valueOf(cleanedUp));

    return cleanedUp;
  }
460418
private void cleanup() throws IOException {
        JarFileManager.INSTANCE.close();
        TempFileManager.INSTANCE.close();
        MavenResolvers.close();
    }
872926
function cleanup (exitCode) {
  if(_disabled) {
    return q.resolve();
  }

  var defer = q.defer();

  _readRunIdFile().then(function (run) {
    _logMessage('test finished. Your results can be viewed at: ' +
      'http://' + _hostname + ':' + _port + '/#/' + run.project_id + '/' + run.suite_id + '/' + run.run_id + '/rp');
    fs.unlink(RUN_PID_FILE, function (err) {
      if (err) {
        defer.reject(err);
      } else {
        defer.resolve();
      }
    });
  });

  return defer.promise;
}
1307238
def _fallback_cleanups(self):
        '''
        
        '''
        # Add an extra fallback in case a forked process leaks through
        multiprocessing.active_children()

        # Cleanup Windows threads
        if not salt.utils.platform.is_windows():
            return
        for thread in self.win_proc:
            if not thread.is_alive():
                thread.join()
                try:
                    self.win_proc.remove(thread)
                    del thread
                except (ValueError, NameError):
                    pass
777006
@Override
  public void cleanup() {
    // @formatter:off
    this
      .setMLSupporter(null)
      .setStatisticsSupporter(null)
      .setIndexingHandler(null)
      .setJoinsHandler(null)
      .setMetaDataHandler(null)
      .setMiscellanyHandler(null)
      .setMissingDataHandler(null)
      .setMutabilityHandler(null)
      .setSqlHandler(null)
      .setPersistenceHandler(null)
      .setRepresentationHandler(null)
      .setReshapingHandler(null)
      .setSchemaHandler(null)
      .setStreamingDataHandler(null)
      .setTimeSeriesHandler(null)
      ;
    // @formatter:on
  }
1125158
def cleanup(self):
        '''
        
        '''
        self.debug("Cleanup called on Site.")
        if not self.connections:
            return defer.succeed(None)
        self.debug("Waiting for all the connections to close.")
        result = self._notifier.wait('idle')
        for connection in self.connections:
            connection.persistent = False
            if not connection.requests:
                connection.transport.loseConnection()
            else:
                request = connection.requests[0]
                peer = connection.transport.getPeer()
                self.debug("Site is still processing a %s request from %s:%s"
                           " to path: %s. It will be given a time to finish",
                           request.method, peer.host, peer.port, request.path)
        return result
550106
public void cleanup() throws ResourceException {

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.entry(this, TRACE, "cleanup");
        }

        // Invalidate any currently associated connections
        for (Iterator iterator = _connections.iterator(); iterator.hasNext();) {

            final SibRaConnection connection = (SibRaConnection) iterator
                    .next();
            connection.invalidate();

        }

        // If we have a connection exception then we must have hit a problem with getting the
        // physical connection. We need to throw an exception here to force the destroy of this
        // managed connection else it goes in the free pool. I better solution would be to expose
        // an api that we can call on jca, this is work in progress.
        if (_connectionException != null)
        {
          //The string used here is searched for by jca so that it won't log the error
            ResourceException exception = new ResourceException("Skip logging for this failing connection");
            if (TRACE.isEventEnabled()) {
              SibTr.exception(this, TRACE, exception);
            }
            throw exception;
        }

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.exit(this, TRACE, "cleanup");
        }

    }
1191901
def clean(self):
        
        if self.cleaners:
            yield from asyncio.wait([x() for x in self.cleaners],
                                    loop=self.loop)
554265
static function cleanup()
    {
        $availableHandlers = eZNotificationEventFilter::availableHandlers();

        $db = eZDB::instance();
        $db->begin();
        foreach( $availableHandlers as $handler )
        {
            if ( $handler !== false )
            {
                $handler->cleanup();
            }
        }
        $db->commit();
    }