[R] How to clear R memory in a for loop
William Dunlap
wdunlap at tibco.com
Mon Oct 20 18:53:27 CEST 2014
tuneR::readMP3 may not be allocating (or freeing) memory correctly. On both
Linux and Windows I get the following (where 'jingle.mp3' is a sample mp3 that
comes with Processing 2.1 which has a quarter million samples in it). If I do
this as a sequence of top-level expression instead of as a for loop R does not
crash. Perhaps you should talk with tuneR's maintainer, who could run valgrind
over it.
> library(tuneR)
tuneR >= 1.0 has changed its Wave class definition.
Use updateWave(object) to convert Wave objects saved with previous
versions of tuneR.
> b <- readMP3("jingle.mp3")
> for(i in 1:100){cat(i,"");b <- readMP3("jingle.mp3")}
1 2
*** caught segfault ***
address 0x3a81000, cause 'memory not mapped'
Traceback:
1: .Call("do_read_mp3", data, package = "tuneR")
2: readMP3("jingle.mp3")
Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Mon, Oct 20, 2014 at 9:25 AM, Jeff Newmiller
<jdnewmil at dcn.davis.ca.us> wrote:
> It is your responsibility (not mine) to simplify your example to the point where it is small, self-contained, and reproducible (see the footer of this message). In fact, doing so often highlights the issue to you before you share it. If any old downloadable mp3 file can be used to reproduce the problem then you would not need to share yours. (Note that this list strips off most attachments, so links are better anyway.)
>
> I suspect that one file read repeatedly might create the problem... if it doesn't, then that would be helpful to know. In any event, your "example" is missing the key element of repetition, so it is not hardly reproducible. The extra things you are doing to make it loop are likely to be important here.
> ---------------------------------------------------------------------------
> Jeff Newmiller The ..... ..... Go Live...
> DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
> Live: OO#.. Dead: OO#.. Playing
> Research Engineer (Solar/Batteries O.O#. #.O#. with
> /Software/Embedded Controllers) .OO#. .OO#. rocks...1k
> ---------------------------------------------------------------------------
> Sent from my phone. Please excuse my brevity.
>
> On October 20, 2014 9:05:45 AM PDT, Dimitri Liakhovitski <dimitri.liakhovitski at gmail.com> wrote:
>>Jeff,
>>
>>here is what I do with each file using library(tuneR):
>>
>>b<-readMP3("cairnomount.mp3")
>>myrange<-range(b at left)
>>write.table(myrange,"x myrange.txt",sep="\t")
>>
>>Would you like me to attach a bunch of large mp3 files?
>>I don't feel I have the right to clog people's inboxes with large
>>files.
>>
>>Thanks!
>>
>>
>>
>>On Mon, Oct 20, 2014 at 11:40 AM, Jeff Newmiller
>><jdnewmil at dcn.davis.ca.us>
>>wrote:
>>
>>> You don't say what processing you are doing.. the answer to your
>>question
>>> is very likely there. To communicate effectively on this mailing
>>list,
>>> self-contained examples are needed. And in order to not corrupt the
>>example
>>> you will need to post in plain text.
>>>
>>---------------------------------------------------------------------------
>>> Jeff Newmiller The ..... ..... Go
>>Live...
>>> DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live
>>> Go...
>>> Live: OO#.. Dead: OO#..
>>Playing
>>> Research Engineer (Solar/Batteries O.O#. #.O#. with
>>> /Software/Embedded Controllers) .OO#. .OO#.
>>rocks...1k
>>>
>>---------------------------------------------------------------------------
>>> Sent from my phone. Please excuse my brevity.
>>>
>>> On October 20, 2014 8:30:21 AM PDT, Dimitri Liakhovitski <
>>> dimitri.liakhovitski at gmail.com> wrote:
>>> >Dear Rers,
>>> >
>>> >I am trying to run a for-loop in R.
>>> >During each iteration I read in an mp3 file and do some basic
>>> >processing.
>>> >If I do what I need to do for each file one by one - it works fine.
>>> >But once I start running a loop, it soon runs out of memory and
>>says:
>>> >can't
>>> >allocate a vector of size...
>>> >In each iteration of my loop I always overwrite the previously
>>created
>>> >object and do gc().
>>> >
>>> >Any hints on how to fight this?
>>> >
>>> >Thanks a lot!
>>> >
>>> > [[alternative HTML version deleted]]
>>> >
>>> >______________________________________________
>>> >R-help at r-project.org mailing list
>>> >https://stat.ethz.ch/mailman/listinfo/r-help
>>> >PLEASE do read the posting guide
>>> >http://www.R-project.org/posting-guide.html
>>> >and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list