[Cs-dev] Memory leak in array opcodes?
Date | 2014-05-31 04:08 |
From | Michael Gogins |
Subject | [Cs-dev] Memory leak in array opcodes? |
Attachments | None None |
I use code similar to this:
instr BformatDecoder irig init i(gk_BformatDecoder_SpeakerRig) asignal[] init nchnls prints "%5.2f BformatDecoder irig: %d channels: %d\n", p1, irig, lenarray(asignal)
absignal[] init 16 absignal[] inletv "inbformat" if irig == 0 then asignal bformdec1 1, absignal elseif irig == 1 then asignal Bformat2DecodeBinaural, absignal, sr
else asignal bformdec1 irig, absignal endif out asignal endin Here an a-rate array is serving as variable to collect Ambisonics 3-rd order B-format signals. Other instruments and opcodes are sending audio over such variables using the signal flow graph opcodes. I have verified that the signal flow graph opcodes do not allocate, destroy, or re-allocate ARRAYDAT structures or their data members. The signal flow graph opcodes also send and receive a-rate array signals just fine.
However, as Csound runs my test piece, it eats memory until it gets to 2 gigabytes (the limit for a 32 bit CPU architecture program) and then crashes. Regards, Mike
----------------------------------------------------- Michael GoginsIrreducible Productions http://michaelgogins.tumblr.com Michael dot Gogins at gmail dot com |
Date | 2014-05-31 10:17 |
From | Victor Lazzarini |
Subject | Re: [Cs-dev] Memory leak in array opcodes? |
Can you send us a complete, but minimal CSD, demonstrating the problem with which we can test it? The leak could be anywhere really, as there are lots of memory use in this kind of code. If you file this as an issue, it will also help us to keep track of it. ======================== Dr Victor Lazzarini Senior Lecturer NUI Maynooth, Ireland victor dot lazzarini at nuim dot ie On 31 May 2014, at 04:08, Michael Gogins |
Date | 2014-06-03 02:37 |
From | Michael Gogins |
Subject | Re: [Cs-dev] Memory leak in array opcodes? |
Attachments | array_memory_leak_test.csd array_memory_leak_test2.csd None None |
Here is a test case, pretty simple. There are two files, identical except that for spatialization one file uses a UDO that returns an a-rate array, the other file just uses a native opcode.
Both files use the outletv and inletv signal flow graph opcodes to send and receive multi-channel a-rate signals, so the signal flow graph opcodes and arrays as such are proved not the problem. It seems pretty clear that returning an a-rate array from the UDO causes a massive memory leak. Dr. Memory does not report this leak, Csound just exits with error code 0xffffffff.
I need to use a UDO to do the spatialization because I need to add distance cues (doppler, local reverb, early reflections, etc.). I have code for this stuff already. I have entered this as an issue.
Regards, Mike ----------------------------------------------------- Michael GoginsIrreducible Productions http://michaelgogins.tumblr.com Michael dot Gogins at gmail dot com On Sat, May 31, 2014 at 5:17 AM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote: Can you send us a complete, but minimal CSD, demonstrating the problem with which we can test it? |
Date | 2014-06-03 03:32 |
From | Steven Yi |
Subject | Re: [Cs-dev] Memory leak in array opcodes? |
I'm about to go to bed, but the problem is likely due to the copy_value function for arrays, which is used by UDO calling code. The copy_value function for arrays has this comment: // TODO - this is heavy handed to reallocate memory every time, // should rewrite like string_copy_value to just copy values if // there is enough memory This is in Engine/csound_standard_types.c. I think I wrote this code quickly and left that note as a fix. There is certainly no size checking and no memory freeing. I will take a look at rewriting this bit of code tomorrow unless someone beats me to it. On Mon, Jun 2, 2014 at 9:37 PM, Michael Gogins |
Date | 2014-06-03 17:32 |
From | Steven Yi |
Subject | Re: [Cs-dev] Memory leak in array opcodes? |
I've modified the array copy_value function to allocate only when necessary, and to call Free() with the old data when necessary. Before the change, memory was shooting up to 500-800megs before quitting here. With the change, memory started out at 6megs and crept up to 9megs after 1800 seconds. I think this is the correct fix. Michael: I've commented on the github issue. Could you pull and retest? If it's good there, please close out the issue. Thanks! steven On Mon, Jun 2, 2014 at 10:32 PM, Steven Yi |