Cabbage Logo
Back to Cabbage Site

Strings strike?

I’m not sure if this is a bug or is it my bad doing?

I’m appending strings to an array. If I let this code run for a while it fills up the memory really badly and it doesn’t release it after I stop it. Also CPU consumption is not low.

Maybe I’m causing this, but I though it would do the job at i-time and be done with it.
Maybe there is a more clever way of appending strings to array?

**

**

<Cabbage>

form caption("test strings array") size(300, 200), colour(0, 0, 0), pluginId("tsa1")  guiMode("queue")

</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-d -n -+rtmidi=null -M0 -m0d

</CsOptions>
<CsInstruments>

ksmps = 16

//# appendStrings
opcode appendStrings, S[],S[]S
StringsIN[], Snew xin
iN = lenarray(StringsIN)
StringsOUT[] init iN+1

ind = 0
until ind == iN do
    StringsOUT[ind] = StringsIN[ind]
    ind += 1
od
StringsOUT[iN] = Snew

xout StringsOUT
endop

instr 1

Strings[] fillarray "default 1-1"
Strings[] appendStrings Strings, "woodwind - metal barrel"
Strings[] appendStrings Strings, "woodwind - barrel"
Strings[] appendStrings Strings, "woodwind - vocal barrel"
Strings[] appendStrings Strings, "woodwind - metal tube"
Strings[] appendStrings Strings, "deep 1: 1/3-1/6" ; -
Strings[] appendStrings Strings, "deep 2: 1/3-2/3" ; (shallow); -
Strings[] appendStrings Strings, "deep 3" ;(mid); -
Strings[] appendStrings Strings, "deep 4: 1/2-1/4" ; -
Strings[] appendStrings Strings, "shallow 1: 1/2-1/2" ; -
Strings[] appendStrings Strings, "paper 1: 1/2-1" ; -
Strings[] appendStrings Strings, "golden 3-3" ; 0.618 0.618 -
Strings[] appendStrings Strings, "golden 3-5" ; 0.618 1.618 -
Strings[] appendStrings Strings, "flat pan bell 2/3-1/3" ; -
Strings[] appendStrings Strings, "deep 5 (punch: 2/3-1/3)" ; -
Strings[] appendStrings Strings, "woodwind - trombone"
Strings[] appendStrings Strings, "bright: 1-3/2" ; -
Strings[] appendStrings Strings, "organ: 1-2" ; -
Strings[] appendStrings Strings, "tube bell"
Strings[] appendStrings Strings, "organ 1-3" ; -
Strings[] appendStrings Strings, "brass 1-1/2"
Strings[] appendStrings Strings, "brass 1-2"
Strings[] appendStrings Strings, "pan can: 5/4-5/4" ; -
Strings[] appendStrings Strings, "sharp 4/3-1/3" ; -
Strings[] appendStrings Strings, "bell 3/2-3/2" ; -
Strings[] appendStrings Strings, "tube can"
Strings[] appendStrings Strings, "sharp pan bell 3/2-1/3" ; -
Strings[] appendStrings Strings, "clarinet bass"
Strings[] appendStrings Strings, "clarinet alt"
Strings[] appendStrings Strings, "clarinet sopra"
Strings[] appendStrings Strings, "golden 5-3" ; 1.618 0.618
Strings[] appendStrings Strings, "sharper pan bell 5/3-1/3" ; -
Strings[] appendStrings Strings, "brass 2-1"
Strings[] appendStrings Strings, "tin can LFO"
endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z ;starts instrument 1 and runs it for a week
i 1 0 -1;[60*60*24*7]

</CsScore>
</CsoundSynthesizer>

It certainly looks like a memory leak, but I can’t see how it’s being caused by Cabbage. If you run it in a vanilla .csd with the command line version of Csound do you still see the same increase in memory?

How do I do that?

Just take the following code and put it into a .csd, then cd to the directory it’s in from the terminal and round

csound filename.csd

<CsoundSynthesizer>
<CsOptions>
-odac

</CsOptions>
<CsInstruments>

ksmps = 16

//# appendStrings
opcode appendStrings, S[],S[]S
StringsIN[], Snew xin
iN = lenarray(StringsIN)
StringsOUT[] init iN+1

ind = 0
until ind == iN do
    StringsOUT[ind] = StringsIN[ind]
    ind += 1
od
StringsOUT[iN] = Snew

xout StringsOUT
endop

instr 1

Strings[] fillarray "default 1-1"
Strings[] appendStrings Strings, "woodwind - metal barrel"
Strings[] appendStrings Strings, "woodwind - barrel"
Strings[] appendStrings Strings, "woodwind - vocal barrel"
Strings[] appendStrings Strings, "woodwind - metal tube"
Strings[] appendStrings Strings, "deep 1: 1/3-1/6" ; -
Strings[] appendStrings Strings, "deep 2: 1/3-2/3" ; (shallow); -
Strings[] appendStrings Strings, "deep 3" ;(mid); -
Strings[] appendStrings Strings, "deep 4: 1/2-1/4" ; -
Strings[] appendStrings Strings, "shallow 1: 1/2-1/2" ; -
Strings[] appendStrings Strings, "paper 1: 1/2-1" ; -
Strings[] appendStrings Strings, "golden 3-3" ; 0.618 0.618 -
Strings[] appendStrings Strings, "golden 3-5" ; 0.618 1.618 -
Strings[] appendStrings Strings, "flat pan bell 2/3-1/3" ; -
Strings[] appendStrings Strings, "deep 5 (punch: 2/3-1/3)" ; -
Strings[] appendStrings Strings, "woodwind - trombone"
Strings[] appendStrings Strings, "bright: 1-3/2" ; -
Strings[] appendStrings Strings, "organ: 1-2" ; -
Strings[] appendStrings Strings, "tube bell"
Strings[] appendStrings Strings, "organ 1-3" ; -
Strings[] appendStrings Strings, "brass 1-1/2"
Strings[] appendStrings Strings, "brass 1-2"
Strings[] appendStrings Strings, "pan can: 5/4-5/4" ; -
Strings[] appendStrings Strings, "sharp 4/3-1/3" ; -
Strings[] appendStrings Strings, "bell 3/2-3/2" ; -
Strings[] appendStrings Strings, "tube can"
Strings[] appendStrings Strings, "sharp pan bell 3/2-1/3" ; -
Strings[] appendStrings Strings, "clarinet bass"
Strings[] appendStrings Strings, "clarinet alt"
Strings[] appendStrings Strings, "clarinet sopra"
Strings[] appendStrings Strings, "golden 5-3" ; 1.618 0.618
Strings[] appendStrings Strings, "sharper pan bell 5/3-1/3" ; -
Strings[] appendStrings Strings, "brass 2-1"
Strings[] appendStrings Strings, "tin can LFO"
endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z ;starts instrument 1 and runs it for a week
i 1 0 -1;[60*60*24*7]

</CsScore>
</CsoundSynthesizer>

Similar thing.
image

Before reporting it to the Csound guys, can you put in a print a

print iN

just after:

iN = lenarray(StringsIN)

I’m wondering if the array somehow continues to grow and grow, thus causing the leak.

iN doesn’t grow.

Can you reproduce it without the UDO?

what do you mean? print is in the UDO
… ah sorry, I’m not seeing strait any more… I’ll check.

Now it seems to stay at 5.2 MB - so it seems is the UDO mechanism causing memory leaks?

Certainly looks like it. Can you file and issue on the github issue tracker for Csound? Or I can do it. It’s just the barebones Csound file that you nee to share.

I haven’t got a Github account yet. So for now, please go ahead and share the issue.
I tested without whitespaces with the same effect. Here comes a bit brushed file.
test_strings_array_memory.csd (1.1 KB)

https://github.com/csound/csound/issues/1540 :+1:

Thanks! And by the way, why does this continue to print beyond the init pass?

Strings[] init 3
printarray Strings