APIMethod: destroy
nullify references to prevent circular references and memory leaks
427963
function() {
        for (var i=0, len=this.rules.length; i<len; i++) {
            this.rules[i].destroy();
        }
        delete this.rules;
    }
1058208
@Nullable V removeWithWriter(Object key) {
    @SuppressWarnings("unchecked")
    K castKey = (K) key;
    @SuppressWarnings({"unchecked", "rawtypes"})
    Node<K, V>[] node = new Node[1];
    @SuppressWarnings("unchecked")
    V[] oldValue = (V[]) new Object[1];
    RemovalCause[] cause = new RemovalCause[1];

    data.computeIfPresent(nodeFactory.newLookupKey(key), (k, n) -> {
      synchronized (n) {
        oldValue[0] = n.getValue();
        if (oldValue[0] == null) {
          cause[0] = RemovalCause.COLLECTED;
        } else if (hasExpired(n, expirationTicker().read())) {
          cause[0] = RemovalCause.EXPIRED;
        } else {
          cause[0] = RemovalCause.EXPLICIT;
        }
        writer.delete(castKey, oldValue[0], cause[0]);
        n.retire();
      }
      node[0] = n;
      return null;
    });

    if (cause[0] != null) {
      afterWrite(new RemovalTask(node[0]));
      if (hasRemovalListener()) {
        notifyRemoval(castKey, oldValue[0], cause[0]);
      }
    }
    return (cause[0] == RemovalCause.EXPLICIT) ? oldValue[0] : null;
  }
354649
private void delete(ReflectedHandle<K, V> n) {
        if (n.inner == null && free != n) {
            throw new IllegalArgumentException("Invalid handle!");
        }

        if (free == n) {
            free = null;
        } else {
            // delete from inner queue
            AddressableHeap.Handle<K, HandleMap<K, V>> nInner = n.inner;
            ReflectedHandle<K, V> nOuter = nInner.getValue().outer;
            nInner.delete();
            nOuter.inner = null;
            nOuter.minNotMax = false;

            // delete pair from inner queue
            AddressableHeap.Handle<K, HandleMap<K, V>> otherInner = nInner.getValue().otherInner;
            ReflectedHandle<K, V> otherOuter = otherInner.getValue().outer;
            otherInner.delete();
            otherOuter.inner = null;
            otherOuter.minNotMax = false;

            // reinsert either as free or as pair with free
            if (free == null) {
                free = otherOuter;
            } else {
                insertPair(otherOuter, free);
                free = null;
            }
        }
        size--;
    }
1368863
public function destroy()
    {
        // This is not mandatory as GC will free the memory eventually but allows memory to be freed faster
        // by removing circular dependencies.
        if (!empty($this->data)) {
            foreach ($this->data as $data) {
                if ($data instanceof DestroyableObject) {
                    $data->destroy();
                }
            }
        }
        $this->data = [];
        $this->manialinkFactory = null;
    }
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);
    }
1204869
private void clean(Set<Throwable> seenThrowables) {
    // Stack trace cleaning can be disabled using a system property.
    if (isStackTraceCleaningDisabled()) {
      return;
    }

    /*
     * TODO(cpovirk): Consider wrapping this whole method in a try-catch in case there are any bugs.
     * It would be a shame for us to fail to report the "real" assertion failure because we're
     * instead reporting a bug in Truth's cosmetic stack cleaning.
     */

    // Prevent infinite recursion if there is a reference cycle between Throwables.
    if (seenThrowables.contains(throwable)) {
      return;
    }
    seenThrowables.add(throwable);

    StackTraceElement[] stackFrames = throwable.getStackTrace();

    int stackIndex = stackFrames.length - 1;
    for (; stackIndex >= 0 && !isTruthEntrance(stackFrames[stackIndex]); stackIndex--) {
      // Find first frame that enters Truth's world, and remove all above.
    }
    stackIndex += 1;

    int endIndex = 0;
    for (;
        endIndex < stackFrames.length && !isJUnitIntrastructure(stackFrames[endIndex]);
        endIndex++) {
      // Find last frame of setup frames, and remove from there down.
    }
    /*
     * If the stack trace would be empty, the error was probably thrown from "JUnit infrastructure"
     * frames. Keep those frames around (though much of JUnit itself and related startup frames will
     * still be removed by the remainder of this method) so that the user sees a useful stack.
     */
    if (!(stackIndex < endIndex)) {
      endIndex = stackFrames.length;
    }

    for (; stackIndex < endIndex; stackIndex++) {
      StackTraceElementWrapper stackTraceElementWrapper =
          new StackTraceElementWrapper(stackFrames[stackIndex]);
      // Always keep frames that might be useful.
      if (stackTraceElementWrapper.getStackFrameType() == StackFrameType.NEVER_REMOVE) {
        endStreak();
        cleanedStackTrace.add(stackTraceElementWrapper);
        continue;
      }

      // Otherwise, process the current frame for collapsing
      addToStreak(stackTraceElementWrapper);

      lastStackFrameElementWrapper = stackTraceElementWrapper;
    }

    // Close out the streak on the bottom of the stack.
    endStreak();

    // Filter out testing framework and reflective calls from the bottom of the stack
    ListIterator<StackTraceElementWrapper> iterator =
        cleanedStackTrace.listIterator(cleanedStackTrace.size());
    while (iterator.hasPrevious()) {
      StackTraceElementWrapper stackTraceElementWrapper = iterator.previous();
      if (stackTraceElementWrapper.getStackFrameType() == StackFrameType.TEST_FRAMEWORK
          || stackTraceElementWrapper.getStackFrameType() == StackFrameType.REFLECTION) {
        iterator.remove();
      } else {
        break;
      }
    }

    // Replace the stack trace on the Throwable with the cleaned one.
    StackTraceElement[] result = new StackTraceElement[cleanedStackTrace.size()];
    for (int i = 0; i < result.length; i++) {
      result[i] = cleanedStackTrace.get(i).getStackTraceElement();
    }
    throwable.setStackTrace(result);

    // Recurse on any related Throwables that are attached to this one
    if (throwable.getCause() != null) {
      new StackTraceCleaner(throwable.getCause()).clean(seenThrowables);
    }
    for (Throwable suppressed : Platform.getSuppressed(throwable)) {
      new StackTraceCleaner(suppressed).clean(seenThrowables);
    }
  }
523440
function destroy() {
         // allow recycling object properties
         me.pool.push(this.currentTransform);
         this.currentTransform = undefined;
         me.pool.push(this.anchorPoint);
         this.anchorPoint = undefined;
         me.pool.push(this.pos);
         this.pos = undefined;
         me.pool.push(this._absPos);
         this._absPos = undefined;
         me.pool.push(this._bounds);
         this._bounds = undefined;
         this.onVisibilityChange = undefined;

         if (typeof this.mask !== "undefined") {
           me.pool.push(this.mask);
           this.mask = undefined;
         }

         if (typeof this.tint !== "undefined") {
           me.pool.push(this.tint);
           this.tint = undefined;
         }

         this.ancestor = undefined; // destroy the physic body if defined

         if (typeof this.body !== "undefined") {
           this.body.destroy.apply(this.body, arguments);
           this.body = undefined;
         }

         this.onDestroyEvent.apply(this, arguments);
       }
166696
function () {
        // we unlink every member from it's parent (assuming this is their parent)
        this.all().forEach(PropertyList._unlinkItemFromParent);

        this.members.length = 0; // remove all items from list

        // now we remove all items from index reference
        Object.keys(this.reference).forEach(function (key) {
            delete this.reference[key];
        }.bind(this));
    }
291126
protected void clearReference (DObject reffer, String field, int reffedOid)
    {
        // look up the reference vector for the referenced object
        Reference[] refs = _refs.get(reffedOid);
        Reference ref = null;

        if (refs != null) {
            for (int ii = 0; ii < refs.length; ii++) {
                if (refs[ii].equals(reffer.getOid(), field)) {
                    ref = refs[ii];
                    refs[ii] = null;
                    break;
                }
            }
        }

        // if a referred object and referring object are both destroyed without allowing the
        // referred object destruction to process the ObjectRemoved event which is auto-generated,
        // the subsequent destruction of the referring object will attempt to clear the reference
        // to the referred object which no longer exists; so we don't complain about non- existent
        // references if the referree is already destroyed
        if (ref == null && _objects.containsKey(reffedOid)) {
            log.warning("Requested to clear out non-existent reference",
                        "refferOid", reffer.getOid(), "field", field, "reffedOid", reffedOid);

//        } else {
//            log.info("Cleared out reference " + ref + ".");
        }
    }
1066556
public void dispose(int sequence) {
        int index = toIndex(sequence);
        checkSequence(index, sequence);
        if (isTask[index]) {
            callableCounter--;
        }
        ringItems[index] = null;
        isTask[index] = false;
    }
1204932
function cleanup()
    {
        // destroy loop variable(s)
        foreach ( $this->LoopVariablesNames as $varName )
            $this->Tpl->unsetVariable( $varName, $this->RootNamespace );
    }
515815
def delete_reference(self, opaque_ref, global_ref=False):
        
        opaque_ref_value = self._get_reference_value(opaque_ref)
        if global_ref:
            del self.global_refs[opaque_ref_value]
        else:
            del self.local_refs[opaque_ref_value]
1214432
static <K, V> void nullifyExpirable(ReferenceEntry<K, V> nulled) {
    ReferenceEntry<K, V> nullEntry = nullEntry();
    nulled.setNextExpirable(nullEntry);
    nulled.setPreviousExpirable(nullEntry);
  }
570175
function (inputStream, outputStream, tempPath, tempPath2, err, callback) {
      async.parallel({
        unlink: function(cb) {
          if (!tempPath) {
            return callback(null);
          }
          removeLocalBlob(tempPath, cb);
        },

        unlink2: function(cb) {
          if (!tempPath2) {
            return callback(null);
          }
          removeLocalBlob(tempPath2, cb);
        },

        closeReadStream: function(cb) {
          inputStream.destroy();
          cb();
        },

        closeWriteStream: function(cb) {
          outputStream.destroy();
          cb();
        }
      }, cleanupError => {
        if (err) {
          return callback(err);
        }
        return callback(cleanupError);
      });
    }
1345678
public boolean releaseIfHolds(T referenced)
    {
        Ref ref = references.remove(referenced);
        if (ref != null)
            ref.release();
        return ref != null;
    }
735135
public static void closeSafely(@Nullable Iterable<? extends CloseableReference<?>> references) {
    if (references != null) {
      for (CloseableReference<?> ref : references) {
        closeSafely(ref);
      }
    }
  }
697737
@SuppressWarnings("unchecked")
    private void delete(SoftHandle<K, V> n) {
        if (n.tree == null) {
            throw new IllegalArgumentException("Invalid handle!");
        }

        /*
         * Delete from belonging list. Care must be taken as the tree reference
         * is valid only if the node is the first in the list.
         */
        TreeNode<K, V> tree = n.tree;

        if (tree.cHead != n) {
            /*
             * Not first in list. Each case, remove and leave as ghost element.
             */
            if (n.next != null) {
                n.next.prev = n.prev;
            }
            n.prev.next = n.next;
        } else {
            /*
             * First in list
             */
            SoftHandle<K, V> nNext = n.next;
            tree.cHead = nNext;
            if (nNext != null) {
                /*
                 * More elements exists, remove and leave as ghost element.
                 * Update new first element to point to correct tree.
                 */
                nNext.prev = null;
                nNext.tree = tree;
            } else {
                /*
                 * No more elements, sift.
                 */
                sift(tree);

                /*
                 * If still no elements, remove tree.
                 */
                if (tree.cHead == null) {
                    if (tree.parent instanceof TreeNode) {
                        TreeNode<K, V> p = (TreeNode<K, V>) tree.parent;
                        if (p.left == tree) {
                            p.left = null;
                        } else {
                            p.right = null;
                        }
                    } else {
                        delete((RootListNode<K, V>) tree.parent);
                    }
                }

            }
        }

        n.tree = null;
        n.prev = null;
        n.next = null;

        size--;
    }