miniscript icon indicating copy to clipboard operation
miniscript copied to clipboard

C++ implementation leaks memory whenever a function reference is returned

Open mahocitrus opened this issue 2 years ago • 2 comments

code to trigger it:

a = function
    b = function
    end function
end function

while true
    a
end while

mahocitrus avatar Oct 15 '23 14:10 mahocitrus

It appears that returning a function defined locally automatically causes a reference loop — perhaps because of the outer context binding. The context includes a reference to the function, which includes a reference to the context.

JoeStrout avatar Oct 15 '23 14:10 JoeStrout

I'm not sure at the moment if there is a simple fix for this, short of switching over to some sort of mark-and-sweep GC system.

For the upcoming minor release, let's look for a simple/easy/safe solution for this particular case. If we can find one, great. If not, we'll punt on this for now (and start planning for a more sophisticated GC).

JoeStrout avatar Oct 31 '23 22:10 JoeStrout