MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _force_dereference

Method _force_dereference

lib/sqlalchemy/orm/state.py:514–537  ·  view source on GitHub ↗

Force this InstanceState to act as though its weakref has been GC'ed. this is used for test code that has to test reactions to objects being GC'ed. We can't reliably force GCs to happen under all CI circumstances.

(self)

Source from the content-addressed store, hash-verified

512 self._detach()
513
514 def _force_dereference(self) -> None:
515 """Force this InstanceState to act as though its weakref has
516 been GC'ed.
517
518 this is used for test code that has to test reactions to objects
519 being GC'ed. We can't reliably force GCs to happen under all
520 CI circumstances.
521
522 """
523
524 # if _strong_obj is set, then our object would not be getting
525 # GC'ed (at least within the scope of what we use this for in tests).
526 # so make sure this is not set
527 assert self._strong_obj is None
528
529 obj = self.obj()
530 if obj is None:
531 # object was GC'ed and we're done! woop
532 return
533
534 del obj
535
536 self._cleanup(self.obj)
537 self.obj = lambda: None # type: ignore
538
539 def _cleanup(self, ref: weakref.ref[_O]) -> None:
540 """Weakref callback cleanup.

Calls 1

_cleanupMethod · 0.95