free simple scope-block reference cycles on bytecode exit

This commit is contained in:
dzaima 2021-05-19 00:28:46 +03:00
parent e02142a4c9
commit af9fbb7dc3
2 changed files with 18 additions and 1 deletions

View File

@ -387,7 +387,7 @@ B slash_c2(B t, B w, B x) {
}
B slicev(B x, usz s, usz ia) {
usz xia = a(x)->ia; if (s+ia>xia) thrM("↑/↓: NYI fills");
usz xia = a(x)->ia; assert(s+ia <= xia);
B r = TI(x).slice(x, s);
arr_shVec(r, ia);
return r;

View File

@ -525,6 +525,23 @@ B actualExec(Block* bl, Scope* psc, i32 ga, B* svar) { // consumes svar contents
while (i<ga) { sc->vars[i] = svar[i]; i++; }
while (i<varAm) sc->vars[i++] = bi_noVar;
B r = evalBC(body, sc);
if (sc->refc>1) {
usz innerRef = 1;
for (i = 0; i < varAm; i++) {
B c = sc->vars[i];
if (isVal(c) && v(c)->refc==1) {
u8 t = v(c)->type;
if (t==t_fun_block && c(FunBlock,c)->sc==sc) innerRef++;
else if (t==t_md1_block && c(Md1Block,c)->sc==sc) innerRef++;
else if (t==t_md2_block && c(Md2Block,c)->sc==sc) innerRef++;
}
}
assert(innerRef<=sc->refc);
if (innerRef==sc->refc) {
value_free((Value*)sc);
return r;
}
}
ptr_dec(sc);
return r;
}