# Tag Info

13

Chunks of weak compositions Here is slightly modified version of algorithm used in CombinatoricaNextComposition converted to a LibraryFunction. Needs["CCompilerDriver"] " #include \"WolframLibrary.h\" DLLEXPORT mint WolframLibrary_getVersion() { return WolframLibraryVersion; } DLLEXPORT int WolframLibrary_initialize(WolframLibraryData libData) { ...

5

Compile f and use a memo-ized version of it Since it seems like NIntegrate decides to symbolically evaluate its argument first, I thought I'd force it not to by compiling the function f. This seems to make a significant difference: Clear[f, f1, g] g[x_] = Nest[f[x] + 1./# &, f[x], 500]; f1 = Compile[{x}, Sum[1/100 Erfc[-(x^2/k)], {k, 100}]]; ...

1

ParallelCombine solution. hugeList = Range[0, 2*10^4]; f[x_] := x ParallelCombine[Total[Map[f, #, 1]] &, hugeList, Total[{#}] &] (* 38503 *) Chunks of hugeList will be handed to Total[Map[f, #, 1]] & in parallel. This Total first Maps f onto each element of the list handed to it (a chunk of hugeList) thereby giving a total for the chunk and ...

0

Say you got a list: a = {1.214132,4.54342,12.2354354} and you want to change the precision on the entire list: SetPrecision[#,4]&/@a result: {1.214, 4.543, 12.24}

13

The memory leak in NIntegrate is a bug and has been fixed as of version 10.2.0. Earlier versions would lose around 720 bytes per evaluation for this example, which could not be recovered without restarting the kernel. ClearSystemCache[] should be used to make sure the memory is released. Using version 10.2: NI[z_?NumericQ, b0_?NumericQ] := ...

3

Update 3 As ilian correctly states in the comments, without NIntegrate we get the same picture as shown in the "Update 2" section. It proves that memory grow reflects temporary memory allocation by Table, and ClearSystemCache[] does completely eliminate the memory leak. We can also switch off the caching completely: SetSystemOptions[ "CacheOptions" ...

5

This might come close to your need; Dynamic[Refresh[MemoryInUse[], UpdateInterval -> 1]] This will update every second the amount of memory used by the kernel.

3

In addition to Timing, AbsoluteTiming and RepeatedTiming, in Mathematica version 10, we have BenchmarkPlot from GeneralUtilities` package, which allows us to, not only, see timings for specific expression, but also easily test how it changes with chosen parameter describing said expression. For benchmarking memory usage there's, mentioned by OP, ...

6

tl;dr I think it's a memory leak (bug) and you should report it to Wolfram Support (please do!) According to my reading, you were saying that after importing JSON files many times, the kernel memory usage reported by the operating system (or some task manager program) was growing to unreasonable levels. However, the memory usage reported by the kernel ...

7

So if you have: file = Import[path] then after the file is not needed: Clear[file] e.g.: In[77]:= MemoryInUse[] file = Import[StringJoin[NotebookDirectory[], "IMG_3025.jpg"]]; MemoryInUse[] Clear[file]; MemoryInUse[] Out[77]= 79593488 Out[79]= 115619864 Out[81]= 79591456

Top 50 recent answers are included