Skip to content

Commit 6e418e8

Browse files
Merge pull request #285 from AndreWohnsland/sqlalchemy
fix memory leak in cocktail detail view lifecycle
2 parents c5dec9f + e4e0ee3 commit 6e418e8

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/ui/setup_mainwindow.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,13 @@ def _deprecation_check(self):
135135
def open_cocktail_selection(self, cocktail: Cocktail):
136136
"""Open the cocktail selection screen."""
137137
if self.cocktail_selection is not None:
138+
# Clean up all internal layouts and widgets recursively
139+
DP_CONTROLLER.delete_items_of_layout(self.cocktail_selection.layout())
140+
# Remove from stacked widget
138141
self.container_maker.removeWidget(self.cocktail_selection)
142+
# Schedule for deletion and remove reference
143+
self.cocktail_selection.deleteLater()
144+
self.cocktail_selection = None
139145
self.cocktail_selection = CocktailSelection(
140146
self, cocktail, lambda: self.container_maker.setCurrentWidget(self.cocktail_view)
141147
)
@@ -163,7 +169,9 @@ def open_keyboard(self, le_to_write, max_char_len=30):
163169

164170
def open_progression_window(self, cocktail_type: str = "Cocktail"):
165171
"""Open up the progression window to show the Cocktail status."""
166-
self.progress_window = ProgressScreen(self, cocktail_type)
172+
if self.progress_window is None:
173+
self.progress_window = ProgressScreen(self, cocktail_type)
174+
self.progress_window.show_screen(cocktail_type)
167175

168176
def change_progression_window(self, pb_value: int):
169177
"""Change the value of the progression bar of the ProBarWindow."""
@@ -175,7 +183,7 @@ def close_progression_window(self):
175183
"""Close the progression window at the end of the cycle."""
176184
if self.progress_window is None:
177185
return
178-
self.progress_window.close()
186+
self.progress_window.hide()
179187

180188
def open_team_window(self):
181189
self.team_window = TeamScreen(self)

src/ui/setup_progress_screen.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def __init__(self, parent, cocktail_type="Cocktail"):
1616
DP_CONTROLLER.initialize_window_object(self)
1717
self.PBabbrechen.clicked.connect(interrupt_cocktail)
1818
self.mainscreen = parent
19+
self.show_screen(cocktail_type)
20+
21+
def show_screen(self, cocktail_type="Cocktail"):
22+
"""Show the Progress screen."""
1923
UI_LANGUAGE.adjust_progress_screen(self, cocktail_type)
2024
self.showFullScreen()
2125
DP_CONTROLLER.set_display_settings(self)

0 commit comments

Comments
 (0)