<p dir="auto"><a href="https://groups.google.com/forum/#!topic/julia-users/IHKQVFVWSMY" rel="nofollow">This is from julia-users</a>. The example is:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function g(a)
  if a
    f() = 2
  else
    f() = 3
  end
  return f
end
f = g(true)
f() # Returns 3"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">g</span>(a)
  <span class="pl-k">if</span> a
    <span class="pl-en">f</span>() <span class="pl-k">=</span> <span class="pl-c1">2</span>
  <span class="pl-k">else</span>
    <span class="pl-en">f</span>() <span class="pl-k">=</span> <span class="pl-c1">3</span>
  <span class="pl-k">end</span>
  <span class="pl-k">return</span> f
<span class="pl-k">end</span>
f <span class="pl-k">=</span> <span class="pl-c1">g</span>(<span class="pl-c1">true</span>)
<span class="pl-c1">f</span>() <span class="pl-c"><span class="pl-c">#</span> Returns 3</span></pre></div>
<p dir="auto">What's also interesting is that g(false) in another REPL session gives an error: "f not defined". So in this setup you either get the second function (if you ask for the first one), or you get nothing! This is on Commit <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/JuliaLang/julia/commit/59d153957596c1d798de08427fa97da370119163/hovercard" href="https://github.com/JuliaLang/julia/commit/59d153957596c1d798de08427fa97da370119163"><tt>59d1539</tt></a> (4 days old master).</p>
<p dir="auto">I have been trying to determine why a program that I am running reports a 4x difference in the amount of resident memory that Linux says Julia is requesting versus the output of <code class="notranslate">Base.summarysize()</code>. I am unclear if this is a bug or just my naivete:</p>
<p dir="auto">Declare a new structure with a single <code class="notranslate">Dict</code> child:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="struct Container{K, V}
    child::Dict{K, V}
end"><pre class="notranslate"><span class="pl-k">struct</span> Container{K, V}
    child<span class="pl-k">::</span><span class="pl-c1">Dict{K, V}</span>
<span class="pl-k">end</span></pre></div>
<p dir="auto">Create two examples, each with 1000 byte random data:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="container_1 = Container(Dict(:test =&gt; rand(UInt8, 1000)))
container_2 = Container(Dict(:test =&gt; rand(UInt8, 1000)))"><pre class="notranslate">container_1 <span class="pl-k">=</span> <span class="pl-c1">Container</span>(<span class="pl-c1">Dict</span>(<span class="pl-c1">:test</span> <span class="pl-k">=&gt;</span> <span class="pl-c1">rand</span>(UInt8, <span class="pl-c1">1000</span>)))
container_2 <span class="pl-k">=</span> <span class="pl-c1">Container</span>(<span class="pl-c1">Dict</span>(<span class="pl-c1">:test</span> <span class="pl-k">=&gt;</span> <span class="pl-c1">rand</span>(UInt8, <span class="pl-c1">1000</span>)))</pre></div>
<p dir="auto">Asking for their size yield 1504 and 1504 for <code class="notranslate">container_1</code> and <code class="notranslate">container_2</code>. However,</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Base.summarysize([container_1, container_2])"><pre class="notranslate">Base<span class="pl-k">.</span><span class="pl-c1">summarysize</span>([container_1, container_2])</pre></div>
<p dir="auto">returns 56 bytes rather than a value greater than 1504 + 1504.</p>
<p dir="auto">Note that using standard <code class="notranslate">Dicts</code> works fine:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="dict_1 = Dict(:test =&gt; rand(UInt8, 1000))
dict_2 = Dict(:test =&gt; rand(UInt8, 1000))
println(Base.summarysize(dict_1))
println(Base.summarysize(dict_2))
println(Base.summarysize([dict_1, dict_2]))"><pre class="notranslate">dict_1 <span class="pl-k">=</span> <span class="pl-c1">Dict</span>(<span class="pl-c1">:test</span> <span class="pl-k">=&gt;</span> <span class="pl-c1">rand</span>(UInt8, <span class="pl-c1">1000</span>))
dict_2 <span class="pl-k">=</span> <span class="pl-c1">Dict</span>(<span class="pl-c1">:test</span> <span class="pl-k">=&gt;</span> <span class="pl-c1">rand</span>(UInt8, <span class="pl-c1">1000</span>))
<span class="pl-c1">println</span>(Base<span class="pl-k">.</span><span class="pl-c1">summarysize</span>(dict_1))
<span class="pl-c1">println</span>(Base<span class="pl-k">.</span><span class="pl-c1">summarysize</span>(dict_2))
<span class="pl-c1">println</span>(Base<span class="pl-k">.</span><span class="pl-c1">summarysize</span>([dict_1, dict_2]))</pre></div>
<p dir="auto">Returns, as expected: <code class="notranslate">dict_1</code> =&gt; 1496 bytes, <code class="notranslate">dict_2</code> =&gt; 1496 bytes, and <code class="notranslate">[dict_1, dict_2]</code> =&gt; 3048 bytes.</p>
<p dir="auto">Version info:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Julia Version 1.6.1
Commit 6aaedecc44 (2021-04-23 05:59 UTC)
Platform Info:
  OS: Linux (x86_64-redhat-linux)
  CPU: Intel(R) Core(TM) i5-4460  CPU @ 3.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, haswell)
Environment:
  JULIA_NUM_THREADS = 3"><pre class="notranslate"><code class="notranslate">Julia Version 1.6.1
Commit 6aaedecc44 (2021-04-23 05:59 UTC)
Platform Info:
  OS: Linux (x86_64-redhat-linux)
  CPU: Intel(R) Core(TM) i5-4460  CPU @ 3.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, haswell)
Environment:
  JULIA_NUM_THREADS = 3
</code></pre></div>