Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Linux] ChucK VM does not call destructor function when shred is removed #49

Open
PaulBatchelor opened this issue Feb 16, 2016 · 1 comment

Comments

@PaulBatchelor
Copy link

Hello,

When a ChucK VM is started (with either chuck --loop or chuck --shell), I've noticed that memory isn't being freed when you explicitly remove a shred (as opposed to letting the shred remove itself).

This bug can be seen by placing printf statements in the constructor/destructor functions of a particular ugen (for instance, SinOsc). A testing chuck file could look like this:

SinOsc s => dac; 10::second => now;

Running "+ sine.ck" and letting it remove it self will cause both the ctor and dtor messages to appear. Running "- 1" before the 10 seconds are up will not call the dtor message.

@spencersalazar
Copy link
Member

Hmm, yes this is actually a pretty complicated issue. "- 1" basically stops the running code right where it is, without releasing references to any objects in scope (object destructors are called when all references to the object have been released). To fix this ChucK would need a way to disentangle itself from multiple nested scopes, e.g. for the code

SinOsc s;
1::second => now;

if(maybe)
{
    SinOsc t;
    1::second => now;

    if(maybe)
    {
        SinOsc u;
        1::second => now;

        if(maybe)
        {
            SinOsc v;
            1::second => now;
        }
    }
}

ChucK would need to know which objects are appropriate to ref-release at any point in this code. Given ChucK's VM model, I don't think this is something it knows at run-time, when the -1 would be issued; rather it is all handled at compile-time. We need to add some sort of "escape hatch" that properly releases active references at any scope, or else track which references belong to which scope at run-time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants