Skip to content

Commit 64f0200

Browse files
committed
Explicitly clear figure and do garbage collection
Memory leaks due to Matplotlib circular dependencies: matplotlib/matplotlib#8519
1 parent 67cf8ed commit 64f0200

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎views.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import copy
22
import csv
3+
import gc
34
import io
45
import json
56
import os
@@ -158,7 +159,9 @@ def _generate_figure(usi, extension, **kwargs):
158159
output_filename = os.path.join(
159160
app.config['TEMPFOLDER'], f'{uuid.uuid4()}.{extension}')
160161
plt.savefig(output_filename, bbox_inches='tight')
161-
plt.close("all")
162+
fig.clear()
163+
plt.close(fig)
164+
gc.collect()
162165

163166
return output_filename
164167

@@ -253,7 +256,9 @@ def _generate_mirror_figure(usi1, usi2, extension, **kwargs):
253256
output_filename = os.path.join(
254257
app.config['TEMPFOLDER'], f'{uuid.uuid4()}.{extension}')
255258
plt.savefig(output_filename, bbox_inches='tight')
256-
plt.close("all")
259+
fig.clear()
260+
plt.close(fig)
261+
gc.collect()
257262

258263
return output_filename
259264

0 commit comments

Comments
 (0)