All immutable new classes use a hack to make sure the post-init cleanup occurs.
762160
def _imm_new(cls):
    '''
    
    '''
    imm = object.__new__(cls)
    # Note that right now imm has a normal setattr method;
    # Give any parameter that has one a default value
    params = cls._pimms_immutable_data_['params']
    for (p,dat) in six.iteritems(params):
        dat = dat[0]
        if dat: object.__setattr__(imm, p, dat[0])
    # Clear any values; they are not allowed yet
    _imm_clear(imm)
    # Note that we are initializing...
    dd = object.__getattribute__(imm, '__dict__')
    dd['_pimms_immutable_is_init'] = True
    # That should do it!
    return imm
673385
public function cleanup()
    {
        // unlock everything
        foreach ($this->locks as $lock) {
            flock($lock, LOCK_UN);
            fclose($lock);
        }

        $this->locks = [];
    }
330198
function _flush() {
    for ( const prop in _classes ) {
      if ( _classes.hasOwnProperty( prop ) &&
           _classes[prop] !== _classes.BASE_CLASS &&
           _dom.classList.contains( _classes[prop] ) ) {
        _dom.classList.remove( _classes[prop] );
      }
    }
  }
850095
function(){
    // if we are not initialized, don't bother finalizing
    if (!this._isInitialized){ return; }
    this._isInitialized = false;

    Marionette.triggerMethod.call(this, "before:stop");

    // stop the sub-modules; depth-first, to make sure the
    // sub-modules are stopped / finalized before parents
    _.each(this.submodules, function(mod){ mod.stop(); });

    // run the finalizers
    this._finalizerCallbacks.run(undefined,this);

    // reset the initializers and finalizers
    this._initializerCallbacks.reset();
    this._finalizerCallbacks.reset();

    Marionette.triggerMethod.call(this, "stop");
  }
915668
def pre_process(classes_hash, opts)
      Process::IgnoredClasses.new(classes_hash).process_all!
      Process::GlobalMembers.new(classes_hash, opts).process_all!
      Process::Accessors.new(classes_hash).process_all!
      Process::Ext4Events.new(classes_hash, opts).process_all!
      Process::Enums.new(classes_hash).process_all!
      Process::Overrides.new(classes_hash, opts).process_all!

      classes_hash.values
    end
1176210
function() {
    if ( !this.modifiers ) {
      return;
    }

    this.modifiers.forEach( function( modifier ) {
      if ( classList.contains( this.element, modifier.ui.base ) ) {
        if ( modifier.initialize ) {
          this.initializers.push( modifier.initialize );
          delete modifier.initialize;
        }
        assign( this, modifier );
      }
    }, this );
  }
593067
def _cleanup(self):
        '''
        
        '''
        self._declare_cb = None
        self._delete_cb = None
        super(ExchangeClass, self)._cleanup()
179029
def _cleanup():
    '''
    
    '''
    for inst in _ACTIVE[:]:
        res = inst.isalive()
        if res is not True:
            try:
                _ACTIVE.remove(inst)
            except ValueError:
                # This can happen if two threads create a new Terminal instance
                # It's harmless that it was already removed, so ignore.
                pass
1304614
public static void cleanup ()
  {
    // Reinitialize singletons to the default values
    if (LocaleCache.isInstantiated ())
      LocaleCache.getInstance ().reinitialize ();
    if (CountryCache.isInstantiated ())
      CountryCache.getInstance ().reinitialize ();
    if (LanguageCache.isInstantiated ())
      LanguageCache.getInstance ().reinitialize ();
    if (SerializationConverterRegistry.isInstantiated ())
      SerializationConverterRegistry.getInstance ().reinitialize ();
    if (MimeTypeDeterminator.isInstantiated ())
      MimeTypeDeterminator.getInstance ().reinitialize ();
    if (ThirdPartyModuleRegistry.isInstantiated ())
      ThirdPartyModuleRegistry.getInstance ().reinitialize ();
    if (TypeConverterRegistry.isInstantiated ())
      TypeConverterRegistry.getInstance ().reinitialize ();
    if (URLProtocolRegistry.isInstantiated ())
      URLProtocolRegistry.getInstance ().reinitialize ();
    if (EqualsImplementationRegistry.isInstantiated ())
      EqualsImplementationRegistry.getInstance ().reinitialize ();
    if (HashCodeImplementationRegistry.isInstantiated ())
      HashCodeImplementationRegistry.getInstance ().reinitialize ();

    // Clear caches
    if (DefaultTextResolver.isInstantiated ())
      DefaultTextResolver.getInstance ().clearCache ();
    EnumHelper.clearCache ();
    ResourceBundleHelper.clearCache ();
    if (RegExCache.isInstantiated ())
      RegExCache.getInstance ().clearCache ();
    CollatorHelper.clearCache ();
    LocaleHelper.clearCache ();
    StatisticsManager.clearCache ();
    SystemProperties.clearWarnedPropertyNames ();
    if (ImageDataManager.isInstantiated ())
      ImageDataManager.getInstance ().clearCache ();

    // Clean this one last as it is used in equals and hashCode implementations!
    ClassHierarchyCache.clearCache ();
  }
710740
def _teardown(self):
        '''
        
        '''
        # __new__ is a super-special case in that even when stubbing a class
        # which implements its own __new__ and subclasses object, the
        # "Class.__new__" reference is a staticmethod and not a method (or
        # function). That confuses the "was_object_method" logic in
        # StubFunction which then fails to delattr and from then on the class
        # is corrupted. So skip that teardown and use a __new__-specific case.
        setattr(self._instance, self._attr, staticmethod(self._new))
        StubNew._cache.pop(self._type)
121737
private static RenameHandler createInstance() {
        // log errors to System.err, as problems in static initializers can be troublesome to diagnose
        RenameHandler instance = create(false);
        try {
            // calling loadFromClasspath() is the best option even though it mutates INSTANCE
            // only serious errors will be caught here, most errors will log from parseRenameFile()
            instance.loadFromClasspath();

        } catch (IllegalStateException ex) {
            System.err.println("ERROR: " + ex.getMessage());
            ex.printStackTrace();
        } catch (Throwable ex) {
            System.err.println("ERROR: Failed to load Renamed.ini files: " + ex.getMessage());
            ex.printStackTrace();
        }
        return instance;
    }
681397
function (out) {
            out.newBlock("main", 0);
            out.newBlock("classDefinition", 0);
            out.newBlock("prototype", 2);
            out.newBlock("globalVars", 5);
            out.newBlock("initTemplate", 3);
            out.newBlock("classInit", 3);
        }
1060437
function () {
        var mutations = this.mutations;

        // track the change if mutation tracking is enabled
        // do this before deleting the keys
        if (this._postman_enableTracking) {
            this.values.each(function (variable) {
                mutations.track(MUTATIONS.UNSET, variable.key);
            });
        }

        this.values.clear();
    }
876943
public void detectChanges() {
        if (engine.isProdMode()) return;
        // Now check for file modification
        List<TemplateClass> modifieds = new ArrayList<TemplateClass>();
        for (TemplateClass tc : engine.classes().all()) {
            if (tc.refresh()) modifieds.add(tc);
        }
        Set<TemplateClass> modifiedWithDependencies = new HashSet<TemplateClass>();
        modifiedWithDependencies.addAll(modifieds);
        List<ClassDefinition> newDefinitions = new ArrayList<ClassDefinition>();
        boolean dirtySig = false;
        for (TemplateClass tc : modifiedWithDependencies) {
            if (tc.compile() == null) {
                engine.classes().remove(tc);
                currentState = new TemplateClassloaderState();//show others that we have changed..
            } else {
                int sigChecksum = tc.sigChecksum;
                tc.enhance();
                if (sigChecksum != tc.sigChecksum) {
                    dirtySig = true;
                }
                newDefinitions.add(new ClassDefinition(tc.javaClass, tc.enhancedByteCode));
                currentState = new TemplateClassloaderState();//show others that we have changed..
            }
        }
        if (!newDefinitions.isEmpty()) {
            throw new ClassReloadException("Need Reload");
        }
        // Check signature (variable name & annotations aware !)
        if (dirtySig) {
            throw new ClassReloadException("Signature change !");
        }

        // Now check if there is new classCache or removed classCache
        int hash = computePathHash();
        if (hash != this.pathHash) {
            // Remove class for deleted files !!
            for (TemplateClass tc : engine.classes().all()) {
                if (!tc.templateResource.isValid()) {
                    engine.classes().remove(tc);
                    currentState = new TemplateClassloaderState();//show others that we have changed..
                }
            }
            throw new ClassReloadException("Path has changed");
        }
    }
426086
private void makeImmutable() {
        // Make the tags unmodifiable
        event.setTags(Collections.unmodifiableMap(event.getTags()));

        // Make the breadcrumbs unmodifiable
        event.setBreadcrumbs(Collections.unmodifiableList(event.getBreadcrumbs()));

        // Make the contexts unmodifiable
        Map<String, Map<String, Object>> tempContexts = new HashMap<>();
        for (Map.Entry<String, Map<String, Object>> contextEntry : event.getContexts().entrySet()) {
            tempContexts.put(contextEntry.getKey(), Collections.unmodifiableMap(contextEntry.getValue()));
        }
        event.setContexts(Collections.unmodifiableMap(tempContexts));

        // Make the extra properties unmodifiable (everything in it is still mutable though)
        event.setExtra(Collections.unmodifiableMap(event.getExtra()));

        // Make the SentryInterfaces unmodifiable
        event.setSentryInterfaces(Collections.unmodifiableMap(event.getSentryInterfaces()));
    }
1260127
def _cleanup(self):
        '''
        
        '''
        self._declare_cb = None
        self._bind_cb = None
        self._unbind_cb = None
        self._delete_cb = None
        self._purge_cb = None
        super(QueueClass, self)._cleanup()
519730
private void initRepairingHandler(RepairingHandler handler) {
        logger.finest("Initializing repairing handler");

        boolean initialized = false;
        try {
            invalidationMetaDataFetcher.init(handler);
            initialized = true;
        } catch (Exception e) {
            logger.warning(e);
        } finally {
            if (!initialized) {
                initRepairingHandlerAsync(handler);
            }
        }
    }