I was writing a API with a lot of http requests, when I noticed Mathematica was slowly using more and more memory, and after some debugging I think the culprit is URLRead
.
The following code should reproduce the problem,
$HistoryLength = 0;
mem = N@MemoryInUse[];
Do[URLRead["http://wolfram.com", {"StatusCode", "Headers"}];, {i,100}];
N@MemoryInUse[] - mem
215 488.
While a similar block of code with RandomReal
instead produces no significant increase of memory usage. Moreover, ClearSystemCache
will only reduce the memory after the first run on a fresh kernel.
The questions then: Can anybody reproduce these results? Is this expected behaviour? And more importantly, since I plan to continuously run my API, is there a way to reclaim this memory?
Tested on MMA 11.3.0.0 on macOS 10.13.3
0.2 MB
, is it significant? $\endgroup$0.7 MB
per 5 minutes, and since I plan to continuously run the code for days, this will become significant. $\endgroup$URLRead
, growing linearly. Mma 11.3.0 Win7 64. Using a local server andTable[ { Do[URLRead[url, {"StatusCode", "Headers"}];, {i, 10}]; 10 k, N@MemoryInUse[] }, {k, 0, 20} ]
$\endgroup$