The volt view never releases memory

24 Views Asked by At

A beginner volt question here :-).

I’ve created a simple volt app which pulls random images from the file system - a slide show. The image data is retrieved in a server task (in addition to the file path, I want dimensions orientation etc, so I use a ruby library) and then its passed back to the main controller. So I have a method (get_random_pic) in the controller which sets the img path etc on the page for a img tag to use in the view:

<img width="{{page._image_data[3]}}}}" src="{{page._image_data[0]}}">image</img>

(An aside: I am using an array in an effort for the value binding "signals" to arrive at the same time - otherwise the image width updates at a different time to the image path - however its still not synchronous with an array)

Then I use setTimeout in the controller to call the get_random_pic method again (via a button).

setTimeout(function(){ document.getElementById("myButton").click(); }, 5000);

This works perfectly however memory usage never stops growing (e.g. after 20min it will 2GB). I assume this is because each time the image is being loaded in the view, the previous image is orphaned and the GC can’t run. Actually I don’t know enough about JS to come to any intelligent reasons as to why, nor an elegant work around. Maybe I could load up the image in a controller instance method and the img tag references directly the binary (rather than pull via file path from file system), and on each iteration I could set it to nil, but I’m hoping there is nicer solution, before I try that.

0

There are 0 best solutions below