Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 10-17-2018, 07:01 AM   #1
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default ReaScript RAM Usage issue (Lua and File Access) - Bug or Code error ?

Hi !


I got a weird issue with file access in Lua where RAM isn't fully restored after file access.


This cause issue with scripts which process a lot of files.



Demo:






As you can see, even after the script is finished, REAPER Ram usage doesn't decrease. It stay at a certain level.



Repo steps:
  1. have a bug wav file like more than 1Go.
  2. Run the following code with path to your file
    Code:
    FilePath = "H:\\untitled.wav"
    local file = io.open(FilePath,"rb")
    local a = file:read('*a')
    file:close()
  3. check RAM usage
Am I missing something ?


Is it code error or REAPER not optimized for this ?


Thanks for your assistance

EDIT: With IDE closed it seems to return to normal... weird




EDIT2: Well, not always, I tried with a loop wich open a lot of files and RAM wasn't restored at the end of the script, it stays at 2Go usage after script execution which is huge.

Note: I wonder this such issue exist with other type of functions.

Last edited by X-Raym; 10-17-2018 at 07:15 AM.
X-Raym is offline   Reply With Quote
Old 10-17-2018, 07:23 AM   #2
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Does this behavior continue, when you use the garbage-collector-functions of Lua?
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is online now   Reply With Quote
Old 10-17-2018, 08:31 AM   #3
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

It could be the C(++) runtime or the operating system keeping the memory ready for the Reaper process in case a new allocation is going to happen in the near future anyway. It would require some tedious testing to confirm that is happening or if it's a genuine memory leak.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 10-17-2018, 11:20 AM   #4
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

Quote:
It could be the C(++) runtime or the operating system keeping the memory ready for the Reaper process in case a new allocation is going to happen in the near future anyway.
If that is the case that would be problematic cause a script of mine reach memory limitations (it scans a lot of file) and there would be no way to free the RAM back... :S


@mespotine
I tried and there seems to be some success if you reset the variable before that like


Code:
a = ''
collectgarbage()

It works only if the IDE is open, as this seems to be even more problematic in this case.



But for real life situation with complex loops etc, this cannot be a valid solutions, it will litteralu double the code line count... +, I didn't found any success on my complex script, only on this small snippet.


I think this memory issue should be handle by REAPER itself.
X-Raym is offline   Reply With Quote
Old 10-17-2018, 11:42 AM   #5
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by X-Raym View Post
If that is the case that would be problematic cause a script of mine reach memory limitations
The runtime or OS would reserve the memory, not keep it occupied not available for other uses. If another allocation happens, the already reserved memory would be repurposed. Did you check that you actually will run out of memory when reading through multiple files? Also, maybe you could redesign your code to read through the files in smaller chunks?
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 10-17-2018, 12:20 PM   #6
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

@Xenakios
Quote:
Did you check that you actually will run out of memory when reading through multiple files?
It is a user report, yes.


Quote:
Also, maybe you could redesign your code to read through the files in smaller chunks
It already read small chunks,


but I just found what was causing the memory hole in my script.


It was scanning file in a loop using



Code:
local source = reaper.PCM_Source_CreateFromFile( f )

but not
Code:
reaper.PCM_Source_Destroy( source )

The above exemple with file access are still valid though, and is interesting. To keep in mind for extra optimization.
X-Raym is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:13 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.