enthought / enthought/traitsui

TableEditor leaks a TableModel object under PySide.

Open
#319 4 comments 0 reactions 0 assignees View on GitHub
type: bug
Dominant language
Python
Stars
306
Forks
99
PR merge metrics
No merged PRs in 30d

Description

Under Qt4 / PySide, the `TableEditor` creates an uncollectable `TableModel` object.

Here's some code that exercises the bug:
```python
from traits.api import HasStrictTraits, List, Str
from traitsui.api import TableEditor, UItem, View
from traitsui.table_column import ObjectColumn

class Employee(HasStrictTraits):
first_name = Str
last_name = Str

class Department(HasStrictTraits):
employees = List(Employee)

traits_view = View(
UItem(
'employees',
editor=TableEditor(
columns=[
ObjectColumn(name='first_name'),
ObjectColumn(name='last_name'),
],
),
),
)

def main():
demo = Department(
employees=[
Employee(first_name='Jason', last_name='Smith'),
Employee(first_name='Lyn', last_name='Spitz'),
]
)
demo.configure_traits()

if __name__ == '__main__':
import gc
for _ in xrange(4):
main()

while gc.collect():
pass

table_models = [
obj for obj in gc.get_objects()
if type(obj).__name__ == 'TableModel'
]
print "Number of leaked table models: ", len(table_models)
```

When I run the above, after dismissing the UI four times, I get:
```
Number of leaked table models: 4
```
The `TableModel` objects in question have no references to them (excluding the `table_models` list itself), according to `gc.get_referrers`. I suspect that some PySide signal handler is incrementing the reference count of the `TableModel` and never doing the corresponding decrement.

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.