Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break OvertypedType -> BlockVariable -> OverloadedType reference cycle #194

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jrmaddison
Copy link
Contributor

@jrmaddison jrmaddison commented Feb 11, 2025

Use a weakref for OverloadedType.block_variable, accessed indirectly via a property. The result persists for as long as it is used elsewhere (e.g. on the tape, referenced by a Control, etc).

Example use:

ot.create_block_variable()
object_0._block_variable = ot.block_variable
object_1._block_variable = ot.block_variable

First line creates and then immediately destroys a BlockVariable. Second line creates another BlockVariable, holding a reference to it, so that the third line references the same BlockVariable. Net effect: attach a new BlockVariable to ot, hold two references on object_0 and object_1, hold a weak reference on ot.

Could be optimized by adding an OverloadedType.clear_block_variable method to replace the first line of the above example

def clear_block_variable(self):
    self._block_variable = lambda: None

which avoids the creation and immediate destruction of a BlockVariable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant