Why are objects sent with send_data kept in memory?

I am creating a Rails application (5.0.4, Ruby 2.3.3) that creates a PDF file using Prawn and sends it to the user using ActionController send_data, for example:

 # data is a Prawn document    
 send_data data, type: 'application/pdf', disposition: 'inline', filename: 'document.pdf'

      

I noticed on Heroku that the app seems to use more and more memory for every document that is created and submitted. I have verified this on my local machine with some rough tests. Now I put GC.start

after call send_data

and the problem seems to be resolved. The memory always returns to a stable level.

My questions are: send_data

what to do to hold the object for a long time? And shouldn't the garbage collector run "in its own way" from time to time? Heroku shows a constant increase in memory. Thank.

+3


source to share


1 answer


GC will only work when the system is under some memory pressure, especially when it is heap_free_slots

exhausted. You can find out how many are available with GC.stat

. Since you usually don't pay for used memory until you run out of it, there is little point in trying to free up space prematurely. Then the largest space can be reclaimed in the smallest calls to the garbage collector.



+2


source







All Articles