<p dir="auto">This issue was experienced on Linux with the following version info and is related to issue <a href="https://github.com/JuliaLang/julia/issues/25884" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/25884/hovercard">#25884</a> filed by  <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/Mistguy/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/Mistguy">@Mistguy</a> :</p>
<blockquote>
<p dir="auto">Julia Version 1.0.3<br>
Commit <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/JuliaLang/julia/commit/1b5990863deb37993087888b8dd3ed53236107a7/hovercard" href="https://github.com/JuliaLang/julia/commit/1b5990863deb37993087888b8dd3ed53236107a7"><tt>1b59908</tt></a> (2019-01-15 20:28 UTC)<br>
Platform Info:<br>
OS: Linux (x86_64-unknown-linux-gnu)<br>
CPU: Intel(R) Xeon(R) CPU E5-2690 v2 @ 3.00GHz<br>
WORD_SIZE: 64<br>
LIBM: libopenlibm<br>
LLVM: libLLVM-6.0.0 (ORCJIT, ivybridge)</p>
</blockquote>
<p dir="auto">When a dictionary is created in a function or global space that has a matrix as its value, its memory never gets freed for the Linux OS kernel to use.  I tested this in and out of interactive mode with the same effect.<br>
I created the following script to test on different systems and saved it as <code class="notranslate">dictAllocationTest.jl</code> to run it as shown below:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="using InteractiveUtils
versioninfo()

println()
if isinteractive()
	println(&quot;Julia running in interactive mode&quot;)
else
	println(&quot;Julia not running in interactive mode&quot;)
end
println()
totMem = Int64(Sys.total_memory())

println()
if isempty(ARGS)
	println(&quot;Testing in global space&quot;)
else
	println(&quot;Testing inside a function&quot;)
end
println()

function createTestDict(totMem)
	testDict = Dict{Int64, Matrix{Float64}}()
	for i in 1:100000
		push!(testDict, i =&gt; ones(Float64, 100, 100))
	end
	mem2 = totMem - Int64(Sys.free_memory())
	testDict = ()
	return mem2
end

mem1 = totMem - Int64(Sys.free_memory())

if isempty(ARGS)
	testDict = Dict{Int64, Matrix{Float64}}()
	for i in 1:100000
		push!(testDict, i =&gt; ones(Float64, 100, 100))
	end
	mem2 = totMem - Int64(Sys.free_memory())
	testDict = ()
else
	mem2 = createTestDict(totMem)
end

GC.gc()

mem3 = totMem - Int64(Sys.free_memory())

println(&quot;Memory added from dictionary is $((mem2 - mem1)/(10^9)) gigabytes&quot;)
println(&quot;Memory freed from clearing dictionary is $((mem2 - mem3)/(10^9)) gigabytes&quot;)
println(&quot;Final memory usage is $(100*mem3/mem1) % of the original&quot;)
"><pre class="notranslate"><span class="pl-k">using</span> InteractiveUtils
<span class="pl-c1">versioninfo</span>()

<span class="pl-c1">println</span>()
<span class="pl-k">if</span> <span class="pl-c1">isinteractive</span>()
	<span class="pl-c1">println</span>(<span class="pl-s"><span class="pl-pds">"</span>Julia running in interactive mode<span class="pl-pds">"</span></span>)
<span class="pl-k">else</span>
	<span class="pl-c1">println</span>(<span class="pl-s"><span class="pl-pds">"</span>Julia not running in interactive mode<span class="pl-pds">"</span></span>)
<span class="pl-k">end</span>
<span class="pl-c1">println</span>()
totMem <span class="pl-k">=</span> <span class="pl-c1">Int64</span>(Sys<span class="pl-k">.</span><span class="pl-c1">total_memory</span>())

<span class="pl-c1">println</span>()
<span class="pl-k">if</span> <span class="pl-c1">isempty</span>(<span class="pl-c1">ARGS</span>)
	<span class="pl-c1">println</span>(<span class="pl-s"><span class="pl-pds">"</span>Testing in global space<span class="pl-pds">"</span></span>)
<span class="pl-k">else</span>
	<span class="pl-c1">println</span>(<span class="pl-s"><span class="pl-pds">"</span>Testing inside a function<span class="pl-pds">"</span></span>)
<span class="pl-k">end</span>
<span class="pl-c1">println</span>()

<span class="pl-k">function</span> <span class="pl-en">createTestDict</span>(totMem)
	testDict <span class="pl-k">=</span> <span class="pl-c1">Dict</span><span class="pl-c1">{Int64, Matrix{Float64}}</span>()
	<span class="pl-k">for</span> i <span class="pl-k">in</span> <span class="pl-c1">1</span><span class="pl-k">:</span><span class="pl-c1">100000</span>
		<span class="pl-c1">push!</span>(testDict, i <span class="pl-k">=&gt;</span> <span class="pl-c1">ones</span>(Float64, <span class="pl-c1">100</span>, <span class="pl-c1">100</span>))
	<span class="pl-k">end</span>
	mem2 <span class="pl-k">=</span> totMem <span class="pl-k">-</span> <span class="pl-c1">Int64</span>(Sys<span class="pl-k">.</span><span class="pl-c1">free_memory</span>())
	testDict <span class="pl-k">=</span> ()
	<span class="pl-k">return</span> mem2
<span class="pl-k">end</span>

mem1 <span class="pl-k">=</span> totMem <span class="pl-k">-</span> <span class="pl-c1">Int64</span>(Sys<span class="pl-k">.</span><span class="pl-c1">free_memory</span>())

<span class="pl-k">if</span> <span class="pl-c1">isempty</span>(<span class="pl-c1">ARGS</span>)
	testDict <span class="pl-k">=</span> <span class="pl-c1">Dict</span><span class="pl-c1">{Int64, Matrix{Float64}}</span>()
	<span class="pl-k">for</span> i <span class="pl-k">in</span> <span class="pl-c1">1</span><span class="pl-k">:</span><span class="pl-c1">100000</span>
		<span class="pl-c1">push!</span>(testDict, i <span class="pl-k">=&gt;</span> <span class="pl-c1">ones</span>(Float64, <span class="pl-c1">100</span>, <span class="pl-c1">100</span>))
	<span class="pl-k">end</span>
	mem2 <span class="pl-k">=</span> totMem <span class="pl-k">-</span> <span class="pl-c1">Int64</span>(Sys<span class="pl-k">.</span><span class="pl-c1">free_memory</span>())
	testDict <span class="pl-k">=</span> ()
<span class="pl-k">else</span>
	mem2 <span class="pl-k">=</span> <span class="pl-c1">createTestDict</span>(totMem)
<span class="pl-k">end</span>

GC<span class="pl-k">.</span><span class="pl-c1">gc</span>()

mem3 <span class="pl-k">=</span> totMem <span class="pl-k">-</span> <span class="pl-c1">Int64</span>(Sys<span class="pl-k">.</span><span class="pl-c1">free_memory</span>())

<span class="pl-c1">println</span>(<span class="pl-s"><span class="pl-pds">"</span>Memory added from dictionary is <span class="pl-v">$((mem2 <span class="pl-k">-</span> mem1)<span class="pl-k">/</span>(<span class="pl-c1">10</span><span class="pl-k">^</span><span class="pl-c1">9</span>))</span> gigabytes<span class="pl-pds">"</span></span>)
<span class="pl-c1">println</span>(<span class="pl-s"><span class="pl-pds">"</span>Memory freed from clearing dictionary is <span class="pl-v">$((mem2 <span class="pl-k">-</span> mem3)<span class="pl-k">/</span>(<span class="pl-c1">10</span><span class="pl-k">^</span><span class="pl-c1">9</span>))</span> gigabytes<span class="pl-pds">"</span></span>)
<span class="pl-c1">println</span>(<span class="pl-s"><span class="pl-pds">"</span>Final memory usage is <span class="pl-v">$(<span class="pl-c1">100</span><span class="pl-k">*</span>mem3<span class="pl-k">/</span>mem1)</span> % of the original<span class="pl-pds">"</span></span>)
</pre></div>
<p dir="auto">Here are the results of testing it on linux in the global space:</p>
<div class="highlight highlight-text-shell-session notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt; $julia1 dictAllocationTest.jl
Julia Version 1.0.3
Commit 1b5990863d (2019-01-15 20:28 UTC)
Platform Info:
  OS: Linux (x86_64-unknown-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-2690 v2 @ 3.00GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, ivybridge)

Julia not running in interactive mode

Testing in global space
Memory added from dictionary is 8.016703488 gigabytes
Memory freed from clearing dictionary is 0.01390592 gigabytes
Final memory usage is 161.5230175061836 % of the original"><pre class="notranslate">&gt; <span class="pl-s1"><span class="pl-smi">$julia1</span> dictAllocationTest.jl</span>
<span class="pl-c1">Julia Version 1.0.3</span>
<span class="pl-c1">Commit 1b5990863d (2019-01-15 20:28 UTC)</span>
<span class="pl-c1">Platform Info:</span>
<span class="pl-c1">  OS: Linux (x86_64-unknown-linux-gnu)</span>
<span class="pl-c1">  CPU: Intel(R) Xeon(R) CPU E5-2690 v2 @ 3.00GHz</span>
<span class="pl-c1">  WORD_SIZE: 64</span>
<span class="pl-c1">  LIBM: libopenlibm</span>
<span class="pl-c1">  LLVM: libLLVM-6.0.0 (ORCJIT, ivybridge)</span>

<span class="pl-c1">Julia not running in interactive mode</span>

<span class="pl-c1">Testing in global space</span>
<span class="pl-c1">Memory added from dictionary is 8.016703488 gigabytes</span>
<span class="pl-c1">Memory freed from clearing dictionary is 0.01390592 gigabytes</span>
<span class="pl-c1">Final memory usage is 161.5230175061836 % of the original</span></pre></div>
<p dir="auto">and in the function space:</p>
<div class="highlight highlight-text-shell-session notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt; $julia1 dictAllocationTest.jl jkl
Julia Version 1.0.3
Commit 1b5990863d (2019-01-15 20:28 UTC)
Platform Info:
  OS: Linux (x86_64-unknown-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-2690 v2 @ 3.00GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, ivybridge)

Julia not running in interactive mode

Testing inside a function
Memory added from dictionary is 8.023105536 gigabytes
Memory freed from clearing dictionary is 0.0 gigabytes
Final memory usage is 161.65566657769227 % of the original"><pre class="notranslate">&gt; <span class="pl-s1"><span class="pl-smi">$julia1</span> dictAllocationTest.jl jkl</span>
<span class="pl-c1">Julia Version 1.0.3</span>
<span class="pl-c1">Commit 1b5990863d (2019-01-15 20:28 UTC)</span>
<span class="pl-c1">Platform Info:</span>
<span class="pl-c1">  OS: Linux (x86_64-unknown-linux-gnu)</span>
<span class="pl-c1">  CPU: Intel(R) Xeon(R) CPU E5-2690 v2 @ 3.00GHz</span>
<span class="pl-c1">  WORD_SIZE: 64</span>
<span class="pl-c1">  LIBM: libopenlibm</span>
<span class="pl-c1">  LLVM: libLLVM-6.0.0 (ORCJIT, ivybridge)</span>

<span class="pl-c1">Julia not running in interactive mode</span>

<span class="pl-c1">Testing inside a function</span>
<span class="pl-c1">Memory added from dictionary is 8.023105536 gigabytes</span>
<span class="pl-c1">Memory freed from clearing dictionary is 0.0 gigabytes</span>
<span class="pl-c1">Final memory usage is 161.65566657769227 % of the original</span></pre></div>
<p dir="auto">In both cases memory is not freed after calling GC.gc() even after the function call is completed.  In contrast when I test this on macOS the results are very different:</p>
<div class="highlight highlight-text-shell-session notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ $julia1 dictAllocationTest.jl
Julia Version 1.0.3
Commit 099e826241 (2018-12-18 01:34 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin14.5.0)
  CPU: Intel(R) Xeon(R) CPU E5-1650 v2 @ 3.50GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, ivybridge)

Julia not running in interactive mode


Testing in global space

Memory added from dictionary is 8.097398784 gigabytes
Memory freed from clearing dictionary is 7.736045568 gigabytes
Final memory usage is 100.62443512513228 % of the original"><pre class="notranslate">$ <span class="pl-s1"><span class="pl-smi">$julia1</span> dictAllocationTest.jl</span>
<span class="pl-c1">Julia Version 1.0.3</span>
<span class="pl-c1">Commit 099e826241 (2018-12-18 01:34 UTC)</span>
<span class="pl-c1">Platform Info:</span>
<span class="pl-c1">  OS: macOS (x86_64-apple-darwin14.5.0)</span>
<span class="pl-c1">  CPU: Intel(R) Xeon(R) CPU E5-1650 v2 @ 3.50GHz</span>
<span class="pl-c1">  WORD_SIZE: 64</span>
<span class="pl-c1">  LIBM: libopenlibm</span>
<span class="pl-c1">  LLVM: libLLVM-6.0.0 (ORCJIT, ivybridge)</span>

<span class="pl-c1">Julia not running in interactive mode</span>


<span class="pl-c1">Testing in global space</span>

<span class="pl-c1">Memory added from dictionary is 8.097398784 gigabytes</span>
<span class="pl-c1">Memory freed from clearing dictionary is 7.736045568 gigabytes</span>
<span class="pl-c1">Final memory usage is 100.62443512513228 % of the original</span></pre></div>
<div class="highlight highlight-text-shell-session notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ $julia1 dictAllocationTest.jl jkgf
Julia Version 1.0.3
Commit 099e826241 (2018-12-18 01:34 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin14.5.0)
  CPU: Intel(R) Xeon(R) CPU E5-1650 v2 @ 3.50GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, ivybridge)

Julia not running in interactive mode


Testing inside a function

Memory added from dictionary is 8.09453568 gigabytes
Memory freed from clearing dictionary is 7.783051264 gigabytes
Final memory usage is 100.53822059089042 % of the original"><pre class="notranslate">$ <span class="pl-s1"><span class="pl-smi">$julia1</span> dictAllocationTest.jl jkgf</span>
<span class="pl-c1">Julia Version 1.0.3</span>
<span class="pl-c1">Commit 099e826241 (2018-12-18 01:34 UTC)</span>
<span class="pl-c1">Platform Info:</span>
<span class="pl-c1">  OS: macOS (x86_64-apple-darwin14.5.0)</span>
<span class="pl-c1">  CPU: Intel(R) Xeon(R) CPU E5-1650 v2 @ 3.50GHz</span>
<span class="pl-c1">  WORD_SIZE: 64</span>
<span class="pl-c1">  LIBM: libopenlibm</span>
<span class="pl-c1">  LLVM: libLLVM-6.0.0 (ORCJIT, ivybridge)</span>

<span class="pl-c1">Julia not running in interactive mode</span>


<span class="pl-c1">Testing inside a function</span>

<span class="pl-c1">Memory added from dictionary is 8.09453568 gigabytes</span>
<span class="pl-c1">Memory freed from clearing dictionary is 7.783051264 gigabytes</span>
<span class="pl-c1">Final memory usage is 100.53822059089042 % of the original</span></pre></div>
<p dir="auto">On macOS and Windows the memory is freed in both cases.  It does seem however that if GC.gc() is called inside the function then memory is not freed until it is called after the function completes as I do in the script.  At present I don't know how to free the memory without exiting the Julia session all together.</p>
<p dir="auto">This code takes less than a minute to fill the 64GB of my Linux machine:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; versioninfo()
Julia Version 1.0.3
Commit 099e826241 (2018-12-18 01:34 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-5820K CPU @ 3.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, haswell)

julia&gt; for i in 1:100
           @eval function foo()
               [fill(1.0, 2_000_000) for _ in 1:100]
               nothing
           end
           @time @eval foo()
           # GC.gc()   # uncomment this line to fix the issue
       end"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-c1">versioninfo</span>()
Julia Version <span class="pl-c1">1.0</span>.<span class="pl-c1">3</span>
Commit <span class="pl-c1">099e826241</span> (<span class="pl-c1">2018</span><span class="pl-k">-</span><span class="pl-c1">12</span><span class="pl-k">-</span><span class="pl-c1">18</span> <span class="pl-c1">01</span><span class="pl-k">:</span><span class="pl-c1">34</span> UTC)
Platform Info<span class="pl-k">:</span>
  OS<span class="pl-k">:</span> Linux (x86_64<span class="pl-k">-</span>pc<span class="pl-k">-</span>linux<span class="pl-k">-</span>gnu)
  CPU<span class="pl-k">:</span> <span class="pl-c1">Intel</span>(R) <span class="pl-c1">Core</span>(TM) i7<span class="pl-k">-</span><span class="pl-c1">5820</span>K CPU @ <span class="pl-c1">3.30</span>GHz
  WORD_SIZE<span class="pl-k">:</span> <span class="pl-c1">64</span>
  LIBM<span class="pl-k">:</span> libopenlibm
  LLVM<span class="pl-k">:</span> libLLVM<span class="pl-k">-</span><span class="pl-c1">6.0</span>.<span class="pl-c1">0</span> (ORCJIT, haswell)

julia<span class="pl-k">&gt;</span> <span class="pl-k">for</span> i <span class="pl-k">in</span> <span class="pl-c1">1</span><span class="pl-k">:</span><span class="pl-c1">100</span>
           <span class="pl-c1">@eval</span> <span class="pl-k">function</span> <span class="pl-en">foo</span>()
               [<span class="pl-c1">fill</span>(<span class="pl-c1">1.0</span>, <span class="pl-c1">2_000_000</span>) <span class="pl-k">for</span> _ <span class="pl-k">in</span> <span class="pl-c1">1</span><span class="pl-k">:</span><span class="pl-c1">100</span>]
               <span class="pl-c1">nothing</span>
           <span class="pl-k">end</span>
           <span class="pl-c1">@time</span> <span class="pl-c1">@eval</span> <span class="pl-c1">foo</span>()
           <span class="pl-c"><span class="pl-c">#</span> GC.gc()   # uncomment this line to fix the issue</span>
       <span class="pl-k">end</span></pre></div>
<p dir="auto">EDIT: simplified code</p>