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

Fix memory management issue in Cocoa TogaIconView #1190

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/cocoa/toga_cocoa/widgets/internal/cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,16 @@ class TogaIconView(NSTableCellView):

@objc_method
def setup(self):
self.imageView = NSImageView.alloc().init()
self.textField = NSTextField.alloc().init()
image_view = NSImageView.alloc().init()
text_field = NSTextField.alloc().init()

# this will retain image_view and text_field without needing to keep
# a Python reference
self.addSubview(image_view)
self.addSubview(text_field)

self.imageView = image_view
self.textField = text_field

self.textField.cell.lineBreakMode = NSLineBreakMode.byTruncatingTail
self.textField.bordered = False
Expand All @@ -43,9 +51,6 @@ def setup(self):
self.imageView.translatesAutoresizingMaskIntoConstraints = False
self.textField.translatesAutoresizingMaskIntoConstraints = False

self.addSubview(self.imageView)
self.addSubview(self.textField)

# center icon vertically in cell
self.iv_vertical_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # NOQA:E501
self.imageView, NSLayoutAttributeCenterY,
Expand Down