Skip to content

Commit

Permalink
Merge pull request #33 from youandvern/update-figure-temp-file-memory
Browse files Browse the repository at this point in the history
Fix potential memory bloat with unclosed temp files
  • Loading branch information
youandvern authored Dec 6, 2024
2 parents 0b6a927 + bb8f3eb commit 545798a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions efficalc/base_definitions/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def __init__(self, figure, caption: str = None, full_width: bool = False):

def load_image_data(self) -> bytes:
"""Loads the image data from the Matplotlib figure object as bytes."""
tmp_file = BytesIO()
self.figure.savefig(tmp_file, format="png")
return tmp_file.getvalue()
with BytesIO() as tmp_file:
self.figure.savefig(tmp_file, format="png")
return tmp_file.getvalue()


class FigureFromFile(FigureBase):
Expand Down

0 comments on commit 545798a

Please sign in to comment.