enthought / enthought/traits

sync_traits creates reference cycles.

Open
#69 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
462
Forks
90
PR merge metrics
No merged PRs in 30d

Description

The `sync_traits` method on `HasTraits` objects creates reference cycles. In the script below, the `create_cycles` function creates two cycles that won't get collected until the cyclic garbage collector runs. See the attached image for the details of the cycles.

```
import gc

import refcycle

from traits.api import HasStrictTraits, HasTraits, Instance, Str

class Eggs(HasStrictTraits):
spam = Str

class Sandwich(HasStrictTraits):
spam = Str

def create_cycles():
sandwich = Sandwich()
eggs = Eggs()
sandwich.sync_trait('spam', eggs)

def main():
gc.disable()
gc.collect()
create_cycles()
garbage = refcycle.garbage()
print "garbage: ", garbage
with open('garbage.gv', 'w') as f:
f.write(garbage.to_dot())

if __name__ == '__main__':
main()
```

![garbage](https://f.cloud.github.com/assets/662003/774093/1098e19c-e94c-11e2-86f1-46a48111e90e.png)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.