Csound Csound-dev Csound-tekno Search About

[Cs-dev] Memory leak in array opcodes?

Date2014-05-31 04:08
FromMichael Gogins
Subject[Cs-dev] Memory leak in array opcodes?
AttachmentsNone  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 Gogins
Irreducible Productions
http://michaelgogins.tumblr.com
Michael dot Gogins at gmail dot com

Date2014-05-31 10:17
FromVictor Lazzarini
SubjectRe: [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  wrote:

> 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 Gogins
> Irreducible Productions
> http://michaelgogins.tumblr.com
> Michael dot Gogins at gmail dot com
> ------------------------------------------------------------------------------
> Time is money. Stop wasting it! Get your web API in 5 minutes.
> www.restlet.com/download
> http://p.sf.net/sfu/restlet_______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel


------------------------------------------------------------------------------
Time is money. Stop wasting it! Get your web API in 5 minutes.
www.restlet.com/download
http://p.sf.net/sfu/restlet
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2014-06-03 02:37
FromMichael Gogins
SubjectRe: [Cs-dev] Memory leak in array opcodes?
Attachmentsarray_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 Gogins
Irreducible 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?
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 <michael.gogins@gmail.com> wrote:

> 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 Gogins
> Irreducible Productions
> http://michaelgogins.tumblr.com
> Michael dot Gogins at gmail dot com
> ------------------------------------------------------------------------------
> Time is money. Stop wasting it! Get your web API in 5 minutes.
> www.restlet.com/download
> http://p.sf.net/sfu/restlet_______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel


------------------------------------------------------------------------------
Time is money. Stop wasting it! Get your web API in 5 minutes.
www.restlet.com/download
http://p.sf.net/sfu/restlet
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel


Date2014-06-03 03:32
FromSteven Yi
SubjectRe: [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  wrote:
> 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 Gogins
> Irreducible Productions
> http://michaelgogins.tumblr.com
> Michael dot Gogins at gmail dot com
>
>
> On Sat, May 31, 2014 at 5:17 AM, Victor Lazzarini 
> wrote:
>>
>> 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  wrote:
>>
>> > 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 Gogins
>> > Irreducible Productions
>> > http://michaelgogins.tumblr.com
>> > Michael dot Gogins at gmail dot com
>> >
>> > ------------------------------------------------------------------------------
>> > Time is money. Stop wasting it! Get your web API in 5 minutes.
>> > www.restlet.com/download
>> >
>> > http://p.sf.net/sfu/restlet_______________________________________________
>> > Csound-devel mailing list
>> > Csound-devel@lists.sourceforge.net
>> > https://lists.sourceforge.net/lists/listinfo/csound-devel
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Time is money. Stop wasting it! Get your web API in 5 minutes.
>> www.restlet.com/download
>> http://p.sf.net/sfu/restlet
>> _______________________________________________
>> Csound-devel mailing list
>> Csound-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>
>
>
> ------------------------------------------------------------------------------
> Learn Graph Databases - Download FREE O'Reilly Book
> "Graph Databases" is the definitive new guide to graph databases and their
> applications. Written by three acclaimed leaders in the field,
> this first edition is now available. Download your free book today!
> http://p.sf.net/sfu/NeoTech
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel
>

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their 
applications. Written by three acclaimed leaders in the field, 
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2014-06-03 17:32
FromSteven Yi
SubjectRe: [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  wrote:
> 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  wrote:
>> 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 Gogins
>> Irreducible Productions
>> http://michaelgogins.tumblr.com
>> Michael dot Gogins at gmail dot com
>>
>>
>> On Sat, May 31, 2014 at 5:17 AM, Victor Lazzarini 
>> wrote:
>>>
>>> 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  wrote:
>>>
>>> > 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 Gogins
>>> > Irreducible Productions
>>> > http://michaelgogins.tumblr.com
>>> > Michael dot Gogins at gmail dot com
>>> >
>>> > ------------------------------------------------------------------------------
>>> > Time is money. Stop wasting it! Get your web API in 5 minutes.
>>> > www.restlet.com/download
>>> >
>>> > http://p.sf.net/sfu/restlet_______________________________________________
>>> > Csound-devel mailing list
>>> > Csound-devel@lists.sourceforge.net
>>> > https://lists.sourceforge.net/lists/listinfo/csound-devel
>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Time is money. Stop wasting it! Get your web API in 5 minutes.
>>> www.restlet.com/download
>>> http://p.sf.net/sfu/restlet
>>> _______________________________________________
>>> Csound-devel mailing list
>>> Csound-devel@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Learn Graph Databases - Download FREE O'Reilly Book
>> "Graph Databases" is the definitive new guide to graph databases and their
>> applications. Written by three acclaimed leaders in the field,
>> this first edition is now available. Download your free book today!
>> http://p.sf.net/sfu/NeoTech
>> _______________________________________________
>> Csound-devel mailing list
>> Csound-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>>

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their 
applications. Written by three acclaimed leaders in the field, 
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net