MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _force_dereference

Method _force_dereference

lib/sqlalchemy/orm/state.py:515–538  ·  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

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

Calls 1

_cleanupMethod · 0.95