about summary refs log tree commit diff stats
path: root/html/037abandon.cc.html
blob: 3c1d2c2f34db916d580859e11db9f7aa4c94f80f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - 037abandon.cc</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v2">
<meta name="syntax" content="cpp">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; }
body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 12pt; font-size: 1em; }
.Constant { color: #00a0a0; }
.cSpecial { color: #008000; }
.muRecipe { color: #ff8700; }
.Comment { color: #9090ff; }
.Delimiter { color: #800080; }
.Special { color: #c00000; }
.traceContains { color: #008000; }
.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; }
.muData { color: #ffff00; }
.CommentedCode { color: #6c6c6c; }
.Identifier { color: #fcb165; }
-->
</style>

<script type='text/javascript'>
<!--

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">//: Reclaiming memory when it's no longer used.</span>
<span class="Comment">//: The top of the address layer has the complete life cycle of memory.</span>

<span class="Delimiter">:(scenario new_reclaim)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:address:num<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Constant">number:type</span>
  <span class="Constant">2</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">1</span>:address:num  <span class="Comment"># because 1 will get reset during abandon below</span>
  <span class="Constant">1</span>:address:num<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>  <span class="Comment"># abandon</span>
  <span class="Constant">3</span>:address:num<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Constant">number:type</span>  <span class="Comment"># must be same size as abandoned memory to reuse</span>
  <span class="Constant">4</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">3</span>:address:num
  <span class="Constant">5</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal <span class="Constant">2</span>:num<span class="Delimiter">,</span> <span class="Constant">4</span>:num
]
<span class="Comment"># both allocations should have returned the same address</span>
<span class="traceContains">+mem: storing 1 in location 5</span>

<span class="Delimiter">:(before &quot;End Decrement Refcount(old_address, payload_type, payload_size)&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>old_refcount == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
  trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">&quot;mem&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;automatically abandoning &quot;</span> &lt;&lt; old_address &lt;&lt; end<span class="Delimiter">();</span>
  abandon<span class="Delimiter">(</span>old_address<span class="Delimiter">,</span> payload_type<span class="Delimiter">,</span> payload_size<span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Comment">//: When abandoning addresses we'll save them to a 'free list', segregated by size.</span>

<span class="Delimiter">:(before &quot;End routine Fields&quot;)</span>
map&lt;<span class="Normal">int</span><span class="Delimiter">,</span> <span class="Normal">int</span>&gt; free_list<span class="Delimiter">;</span>

<span class="Delimiter">:(code)</span>
<span class="Normal">void</span> abandon<span class="Delimiter">(</span><span class="Normal">int</span> address<span class="Delimiter">,</span> <span class="Normal">const</span> type_tree* payload_type<span class="Delimiter">,</span> <span class="Normal">int</span> payload_size<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">&quot;abandon&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;updating refcounts inside &quot;</span> &lt;&lt; address &lt;&lt; <span class="Constant">&quot;: &quot;</span> &lt;&lt; to_string<span class="Delimiter">(</span>payload_type<span class="Delimiter">)</span> &lt;&lt; end<span class="Delimiter">();</span>
<span class="CommentedCode">//?   Total_free += size;</span>
<span class="CommentedCode">//?   ++Num_free;</span>
<span class="CommentedCode">//?   cerr &lt;&lt; &quot;abandon: &quot; &lt;&lt; size &lt;&lt; '\n';</span>
  <span class="Comment">// decrement any contained refcounts</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_array<span class="Delimiter">(</span>payload_type<span class="Delimiter">))</span> <span class="Delimiter">{</span>
    reagent element<span class="Delimiter">;</span>
    element<span class="Delimiter">.</span>type = copy_array_element<span class="Delimiter">(</span>payload_type<span class="Delimiter">);</span>
    <span class="Normal">int</span> array_length = get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> address+<span class="Comment">/*</span><span class="Comment">skip refcount</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">);</span>
    assert<span class="Delimiter">(</span>element<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>name != <span class="Constant">&quot;array&quot;</span><span class="Delimiter">);</span>
    <span class="Normal">int</span> element_size = size_of<span class="Delimiter">(</span>element<span class="Delimiter">);</span>
    <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i &lt; array_length<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
      element<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>address + <span class="Comment">/*</span><span class="Comment">skip refcount and length</span><span class="Comment">*/</span><span class="Constant">2</span> + i*element_size<span class="Delimiter">);</span>
      decrement_any_refcounts<span class="Delimiter">(</span>element<span class="Delimiter">);</span>
    <span class="Delimiter">}</span>
  <span class="Delimiter">}</span>
  <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_container<span class="Delimiter">(</span>payload_type<span class="Delimiter">)</span> || is_mu_exclusive_container<span class="Delimiter">(</span>payload_type<span class="Delimiter">))</span> <span class="Delimiter">{</span>
    reagent tmp<span class="Delimiter">;</span>
    tmp<span class="Delimiter">.</span>type = <span class="Normal">new</span> type_tree<span class="Delimiter">(</span>*payload_type<span class="Delimiter">);</span>
    tmp<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>address + <span class="Comment">/*</span><span class="Comment">skip refcount</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">);</span>
    decrement_any_refcounts<span class="Delimiter">(</span>tmp<span class="Delimiter">);</span>
  <span class="Delimiter">}</span>
  <span class="Comment">// clear memory</span>
  <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> curr = address<span class="Delimiter">;</span> curr &lt; address+payload_size<span class="Delimiter">;</span> ++curr<span class="Delimiter">)</span>
    put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> curr<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span>
  <span class="Comment">// append existing free list to address</span>
  trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">&quot;abandon&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;saving &quot;</span> &lt;&lt; address &lt;&lt; <span class="Constant">&quot; in free-list of size &quot;</span> &lt;&lt; payload_size &lt;&lt; end<span class="Delimiter">();</span>
  put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> address<span class="Delimiter">,</span> get_or_insert<span class="Delimiter">(</span>Current_routine<span class="Delimiter">-&gt;</span>free_list<span class="Delimiter">,</span> payload_size<span class="Delimiter">));</span>
  put<span class="Delimiter">(</span>Current_routine<span class="Delimiter">-&gt;</span>free_list<span class="Delimiter">,</span> payload_size<span class="Delimiter">,</span> address<span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(after &quot;Allocate Special-cases&quot;)</span>
<span class="Normal">if</span> <span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Current_routine<span class="Delimiter">-&gt;</span>free_list<span class="Delimiter">,</span> size<span class="Delimiter">))</span> <span class="Delimiter">{</span>
  trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">&quot;abandon&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;picking up space from free-list of size &quot;</span> &lt;&lt; size &lt;&lt; end<span class="Delimiter">();</span>
  <span class="Normal">int</span> result = get_or_insert<span class="Delimiter">(</span>Current_routine<span class="Delimiter">-&gt;</span>free_list<span class="Delimiter">,</span> size<span class="Delimiter">);</span>
  trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">&quot;mem&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;new alloc from free list: &quot;</span> &lt;&lt; result &lt;&lt; end<span class="Delimiter">();</span>
  put<span class="Delimiter">(</span>Current_routine<span class="Delimiter">-&gt;</span>free_list<span class="Delimiter">,</span> size<span class="Delimiter">,</span> get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> result<span class="Delimiter">));</span>
  put<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> result<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span>
  <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> curr = result<span class="Delimiter">;</span> curr &lt; result+size<span class="Delimiter">;</span> ++curr<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> curr<span class="Delimiter">)</span> != <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
      raise &lt;&lt; maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> &lt;&lt; <span class="Constant">&quot;memory in free list was not zeroed out: &quot;</span> &lt;&lt; curr &lt;&lt; <span class="Constant">'/'</span> &lt;&lt; result &lt;&lt; <span class="Constant">&quot;; somebody wrote to us after free!!!</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
      <span class="Identifier">break</span><span class="Delimiter">;</span>  <span class="Comment">// always fatal</span>
    <span class="Delimiter">}</span>
  <span class="Delimiter">}</span>
  <span class="Identifier">return</span> result<span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(scenario new_differing_size_no_reclaim)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:address:num<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Constant">number:type</span>
  <span class="Constant">2</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">1</span>:address:num
  <span class="Constant">1</span>:address:num<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>  <span class="Comment"># abandon</span>
  <span class="Constant">3</span>:address:array:num<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Constant">number:type</span><span class="Delimiter">,</span> <span class="Constant">2</span>  <span class="Comment"># different size</span>
  <span class="Constant">4</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">3</span>:address:array:num
  <span class="Constant">5</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal <span class="Constant">2</span>:num<span class="Delimiter">,</span> <span class="Constant">4</span>:num
]
<span class="Comment"># no reuse</span>
<span class="traceContains">+mem: storing 0 in location 5</span>

<span class="Delimiter">:(scenario new_reclaim_array)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:address:array:num<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Constant">number:type</span><span class="Delimiter">,</span> <span class="Constant">2</span>
  <span class="Constant">2</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">1</span>:address:array:num
  <span class="Constant">1</span>:address:array:num<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>  <span class="Comment"># abandon</span>
  <span class="Constant">3</span>:address:array:num<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Constant">number:type</span><span class="Delimiter">,</span> <span class="Constant">2</span>  <span class="Comment"># same size</span>
  <span class="Constant">4</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">3</span>:address:array:num
  <span class="Constant">5</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal <span class="Constant">2</span>:num<span class="Delimiter">,</span> <span class="Constant">4</span>:num
]
<span class="Comment"># both calls to new returned identical addresses</span>
<span class="traceContains">+mem: storing 1 in location 5</span>

<span class="Delimiter">:(scenario abandon_on_overwrite)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:address:num<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Constant">number:type</span>
  <span class="Comment"># over-writing one allocation with another</span>
  <span class="Constant">1</span>:address:num<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Constant">number:type</span>
  <span class="Constant">1</span>:address:num<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
]
<span class="traceContains">+run: {1: (&quot;address&quot; &quot;number&quot;)} &lt;- new {number: &quot;type&quot;}</span>
<span class="traceContains">+mem: incrementing refcount of 1000: 0 -&gt; 1</span>
<span class="traceContains">+run: {1: (&quot;address&quot; &quot;number&quot;)} &lt;- new {number: &quot;type&quot;}</span>
<span class="traceContains">+mem: automatically abandoning 1000</span>

<span class="Delimiter">:(scenario abandon_after_call)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:address:num<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Constant">number:type</span>
  <span class="Comment"># passing in addresses to recipes increments refcount</span>
  foo <span class="Constant">1</span>:address:num
  <span class="Constant">1</span>:address:num<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
]
<span class="muRecipe">def</span> foo [
  <span class="Constant">2</span>:address:num<span class="Special"> &lt;- </span>next-ingredient
  <span class="Comment"># return does NOT yet decrement refcount; memory must be explicitly managed</span>
  <span class="Constant">2</span>:address:num<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
]
<span class="traceContains">+run: {1: (&quot;address&quot; &quot;number&quot;)} &lt;- new {number: &quot;type&quot;}</span>
<span class="traceContains">+mem: incrementing refcount of 1000: 0 -&gt; 1</span>
<span class="traceContains">+run: foo {1: (&quot;address&quot; &quot;number&quot;)}</span>
<span class="Comment"># leave ambiguous precisely when the next increment happens; a later layer</span>
<span class="Comment"># will mess with that</span>
<span class="traceContains">+mem: incrementing refcount of 1000: 1 -&gt; 2</span>
<span class="traceContains">+run: {2: (&quot;address&quot; &quot;number&quot;)} &lt;- copy {0: &quot;literal&quot;}</span>
<span class="traceContains">+mem: decrementing refcount of 1000: 2 -&gt; 1</span>
<span class="traceContains">+run: {1: (&quot;address&quot; &quot;number&quot;)} &lt;- copy {0: &quot;literal&quot;}</span>
<span class="traceContains">+mem: decrementing refcount of 1000: 1 -&gt; 0</span>
<span class="traceContains">+mem: automatically abandoning 1000</span>

<span class="Delimiter">:(scenario abandon_on_overwrite_array)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">30</span>
  <span class="Comment"># allocate an array</span>
  <span class="Constant">10</span>:address:array:num<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Constant">number:type</span><span class="Delimiter">,</span> <span class="Constant">20</span>
  <span class="Constant">11</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>:address:array:num  <span class="Comment"># doesn't increment refcount</span>
  <span class="Comment"># allocate another array in its place, implicitly freeing the previous allocation</span>
  <span class="Constant">10</span>:address:array:num<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Constant">number:type</span><span class="Delimiter">,</span> <span class="Constant">25</span>
]
<span class="traceContains">+run: {10: (&quot;address&quot; &quot;array&quot; &quot;number&quot;)} &lt;- new {number: &quot;type&quot;}, {25: &quot;literal&quot;}</span>
<span class="Comment"># abandoned array is of old size (20, not 25)</span>
<span class="traceContains">+abandon: saving 1000 in free-list of size 22</span>

<span class="Delimiter">:(scenario refcounts_abandon_address_in_container)</span>
<span class="Comment"># container containing an address</span>
<span class="muData">container</span> foo [
  <span class="Normal">x</span>:address:num
]
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:address:num<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Constant">number:type</span>
  <span class="Constant">2</span>:address:foo<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Constant">foo:type</span>
  *<span class="Constant">2</span>:address:foo<span class="Special"> &lt;- </span>put *<span class="Constant">2</span>:address:foo<span class="Delimiter">,</span> <span class="Constant">x:offset</span><span class="Delimiter">,</span> <span class="Constant">1</span>:address:num
  <span class="Constant">1</span>:address:num<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  <span class="Constant">2</span>:address:foo<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
]
<span class="traceContains">+run: {1: (&quot;address&quot; &quot;number&quot;)} &lt;- new {number: &quot;type&quot;}</span>
<span class="traceContains">+mem: incrementing refcount of 1000: 0 -&gt; 1</span>
<span class="traceContains">+run: {2: (&quot;address&quot; &quot;foo&quot;)} &lt;- new {foo: &quot;type&quot;}</span>
<span class="traceContains">+mem: incrementing refcount of 1002: 0 -&gt; 1</span>
<span class="traceContains">+run: {2: (&quot;address&quot; &quot;foo&quot;), &quot;lookup&quot;: ()} &lt;- put {2: (&quot;address&quot; &quot;foo&quot;), &quot;lookup&quot;: ()}, {x: &quot;offset&quot;}, {1: (&quot;address&quot; &quot;number&quot;)}</span>
<span class="traceContains">+mem: incrementing refcount of 1000: 1 -&gt; 2</span>
<span class="traceContains">+run: {1: (&quot;address&quot; &quot;number&quot;)} &lt;- copy {0: &quot;literal&quot;}</span>
<span class="traceContains">+mem: decrementing refcount of 1000: 2 -&gt; 1</span>
<span class="traceContains">+run: {2: (&quot;address&quot; &quot;foo&quot;)} &lt;- copy {0: &quot;literal&quot;}</span>
<span class="Comment"># start abandoning container containing address</span>
<span class="traceContains">+mem: decrementing refcount of 1002: 1 -&gt; 0</span>
<span class="Comment"># nested abandon</span>
<span class="traceContains">+mem: decrementing refcount of 1000: 1 -&gt; 0</span>
<span class="traceContains">+abandon: saving 1000 in free-list of size 2</span>
<span class="Comment"># actually abandon the container containing address</span>
<span class="traceContains">+abandon: saving 1002 in free-list of size 2</span>

<span class="Comment"># todo: move past dilated reagent</span>
<span class="Delimiter">:(scenario refcounts_abandon_address_in_array)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:address:num<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Constant">number:type</span>
  <span class="Constant">2</span>:address:array:address:num<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Delimiter">{(</span>address number<span class="Delimiter">)</span>: type<span class="Delimiter">},</span> <span class="Constant">3</span>
  *<span class="Constant">2</span>:address:array:address:num<span class="Special"> &lt;- </span>put-index *<span class="Constant">2</span>:address:array:address:num<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">1</span>:address:num
  <span class="Constant">1</span>:address:num<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  <span class="Constant">2</span>:address:array:address:num<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
]
<span class="traceContains">+run: {1: (&quot;address&quot; &quot;number&quot;)} &lt;- new {number: &quot;type&quot;}</span>
<span class="traceContains">+mem: incrementing refcount of 1000: 0 -&gt; 1</span>
<span class="traceContains">+run: {2: (&quot;address&quot; &quot;array&quot; &quot;address&quot; &quot;number&quot;), &quot;lookup&quot;: ()} &lt;- put-index {2: (&quot;address&quot; &quot;array&quot; &quot;address&quot; &quot;number&quot;), &quot;lookup&quot;: ()}, {1: &quot;literal&quot;}, {1: (&quot;address&quot; &quot;number&quot;)}</span>
<span class="traceContains">+mem: incrementing refcount of 1000: 1 -&gt; 2</span>
<span class="traceContains">+run: {1: (&quot;address&quot; &quot;number&quot;)} &lt;- copy {0: &quot;literal&quot;}</span>
<span class="traceContains">+mem: decrementing refcount of 1000: 2 -&gt; 1</span>
<span class="traceContains">+run: {2: (&quot;address&quot; &quot;array&quot; &quot;address&quot; &quot;number&quot;)} &lt;- copy {0: &quot;literal&quot;}</span>
<span class="Comment"># nested abandon</span>
<span class="traceContains">+mem: decrementing refcount of 1000: 1 -&gt; 0</span>
<span class="traceContains">+abandon: saving 1000 in free-list of size 2</span>

<span class="Delimiter">:(scenario refcounts_abandon_address_in_container_in_array)</span>
<span class="Comment"># container containing an address</span>
<span class="muData">container</span> foo [
  <span class="Normal">x</span>:address:num
]
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:address:num<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Constant">number:type</span>
  <span class="Constant">2</span>:address:array:foo<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Constant">foo:type</span><span class="Delimiter">,</span> <span class="Constant">3</span>
  <span class="Constant">3</span>:foo<span class="Special"> &lt;- </span>merge <span class="Constant">1</span>:address:num
  *<span class="Constant">2</span>:address:array:foo<span class="Special"> &lt;- </span>put-index *<span class="Constant">2</span>:address:array:foo<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">3</span>:foo
  <span class="Constant">1</span>:address:num<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  <span class="Constant">3</span>:foo<span class="Special"> &lt;- </span>merge <span class="Constant">0</span>
  <span class="Constant">2</span>:address:array:foo<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
]
<span class="traceContains">+run: {1: (&quot;address&quot; &quot;number&quot;)} &lt;- new {number: &quot;type&quot;}</span>
<span class="traceContains">+mem: incrementing refcount of 1000: 0 -&gt; 1</span>
<span class="traceContains">+run: {3: &quot;foo&quot;} &lt;- merge {1: (&quot;address&quot; &quot;number&quot;)}</span>
<span class="traceContains">+mem: incrementing refcount of 1000: 1 -&gt; 2</span>
<span class="traceContains">+run: {2: (&quot;address&quot; &quot;array&quot; &quot;foo&quot;), &quot;lookup&quot;: ()} &lt;- put-index {2: (&quot;address&quot; &quot;array&quot; &quot;foo&quot;), &quot;lookup&quot;: ()}, {1: &quot;literal&quot;}, {3: &quot;foo&quot;}</span>
<span class="traceContains">+mem: incrementing refcount of 1000: 2 -&gt; 3</span>
<span class="traceContains">+run: {1: (&quot;address&quot; &quot;number&quot;)} &lt;- copy {0: &quot;literal&quot;}</span>
<span class="traceContains">+mem: decrementing refcount of 1000: 3 -&gt; 2</span>
<span class="traceContains">+run: {3: &quot;foo&quot;} &lt;- merge {0: &quot;literal&quot;}</span>
<span class="traceContains">+mem: decrementing refcount of 1000: 2 -&gt; 1</span>
<span class="traceContains">+run: {2: (&quot;address&quot; &quot;array&quot; &quot;foo&quot;)} &lt;- copy {0: &quot;literal&quot;}</span>
<span class="Comment"># nested abandon</span>
<span class="traceContains">+mem: decrementing refcount of 1000: 1 -&gt; 0</span>
<span class="traceContains">+abandon: saving 1000 in free-list of size 2</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->