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

Correct leaks on Switch and Divider on iOS. #2850

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions changes/2849.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A memory leak when using Divider or Switch widgets on iOS was resolved.
9 changes: 9 additions & 0 deletions iOS/src/toga_iOS/widgets/box.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
from rubicon.objc import objc_property
from travertino.size import at_least

from toga_iOS.libs import UIView
from toga_iOS.widgets.base import Widget


class TogaView(UIView):
interface = objc_property(object, weak=True)
impl = objc_property(object, weak=True)


class Box(Widget):
def create(self):
# This should be a TogaView - but making it a TogaView causes segfaults when
# content is added and removed from containers like OptionContainer and
# ScrollContainer.
self.native = UIView.alloc().init()
self.native.interface = self.interface
self.native.impl = self
Expand Down
6 changes: 4 additions & 2 deletions iOS/src/toga_iOS/widgets/divider.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from travertino.size import at_least

from toga_iOS.libs import UIColor, UIView
from toga_iOS.libs import UIColor
from toga_iOS.widgets.base import Widget

from .box import TogaView


class Divider(Widget):
def create(self):
self.native = UIView.alloc().init()
self.native = TogaView.alloc().init()
self.native.interface = self.interface
self.native.impl = self

Expand Down
7 changes: 6 additions & 1 deletion iOS/src/toga_iOS/widgets/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
from toga_iOS.widgets.base import Widget


class TogaStackView(UIStackView):
interface = objc_property(object, weak=True)
impl = objc_property(object, weak=True)


class TogaSwitch(UISwitch):
interface = objc_property(object, weak=True)
impl = objc_property(object, weak=True)
Expand All @@ -26,7 +31,7 @@ class Switch(Widget):
SPACING = 10

def create(self):
self.native = UIStackView.alloc().init()
self.native = TogaStackView.alloc().init()
self.native.interface = self.interface
self.native.impl = self
self.native.axis = UILayoutConstraintAxis.Horizontal
Expand Down
2 changes: 1 addition & 1 deletion testbed/tests/widgets/test_divider.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async def widget():
return toga.Divider()


test_cleanup = build_cleanup_test(toga.Divider, xfail_platforms=("iOS",))
test_cleanup = build_cleanup_test(toga.Divider)


async def test_directions(widget, probe):
Expand Down
2 changes: 1 addition & 1 deletion testbed/tests/widgets/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async def widget():


test_cleanup = build_cleanup_test(
toga.Switch, args=("Hello",), xfail_platforms=("android", "iOS", "linux")
toga.Switch, args=("Hello",), xfail_platforms=("android", "linux")
)


Expand Down