Skip to content

Commit 7bd92ac

Browse files
committed
Fix memory leak with label reuse
1 parent 3915382 commit 7bd92ac

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

adafruit_portalbase/__init__.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -238,25 +238,22 @@ def set_text(self, val, index=0):
238238
elif self._debug:
239239
print("Creating text area with :", string)
240240

241-
if len(string) > 0:
242-
self._text[index]["label"] = Label(
243-
self._fonts[self._text[index]["font"]],
244-
text=string,
245-
scale=self._text[index]["scale"],
246-
)
241+
if len(string.strip()) > 0:
242+
if self._text[index]["label"] is None:
243+
self._text[index]["label"] = Label(
244+
self._fonts[self._text[index]["font"]],
245+
text=string,
246+
scale=self._text[index]["scale"],
247+
)
247248
self._text[index]["label"].color = self._text[index]["color"]
248249
self._text[index]["label"].anchor_point = self._text[index]["anchor_point"]
249250
self._text[index]["label"].anchored_position = self._text[index]["position"]
250251
self._text[index]["label"].line_spacing = self._text[index]["line_spacing"]
251252
elif index_in_splash is not None:
252253
self._text[index]["label"] = None
254+
del self.splash[index_in_splash]
253255

254-
if index_in_splash is not None:
255-
if self._text[index]["label"] is not None:
256-
self.splash[index_in_splash] = self._text[index]["label"]
257-
else:
258-
del self.splash[index_in_splash]
259-
elif self._text[index]["label"] is not None:
256+
if self._text[index]["label"] is not None and index_in_splash is None:
260257
self.splash.append(self._text[index]["label"])
261258

262259
def preload_font(self, glyphs=None, index=0):

0 commit comments

Comments
 (0)