Skip to content

Commit

Permalink
Remove circular reference from OverloadedDict
Browse files Browse the repository at this point in the history
Now KeyOverloads only have a proxy reference to the parent object. This prevents these objects being managed by the generational garbage collector. That was bad since it could keep large AnnData objects in memory. See scverse#360 for more info.
  • Loading branch information
ivirshup committed May 7, 2020
1 parent 2e37bb6 commit 8dfafe2
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion anndata/compat/_overloaded_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from functools import partial
from typing import Any, Callable, Mapping, Optional
from warnings import warn
from weakref import proxy


class KeyOverload:
Expand Down Expand Up @@ -90,7 +91,7 @@ def __init__(self, data: Mapping, *, overloaded: Mapping[Any, KeyOverload]):
self.data = data
self.overloaded = overloaded
for v in overloaded.values():
v.parent = self
v.parent = proxy(self)

def __getitem__(self, key):
if key in self.overloaded:
Expand Down

0 comments on commit 8dfafe2

Please sign in to comment.