Infinite Increasing Memory Usage Until Crash

The reason your script is taking so much memory is because you’re continually creating Scenes, which are quite expensive (and, since you’re using GLMakie, have to be stored on the GPU as well). Instead of creating and then saving individual scenes, you can use Makie’s inbuilt animation capabilities to achieve the same thing.

First, here’s an example of your code changed to use Observables (such that you only mutate a single Scene, and don’t create multiple Scenes):

function isosurface3D(data,timeend)
    scene = volume(data[:,:,:,1],algorithm=:iso)
    volumeplot = scene.plots[end] # the last plot plotted to the Scene.
    for i=1:timeend
        volumeplot[4][] = data[:, :, :, i] # update the data of the plot
        Makie.save("scene_$i.png", scene) # save each frame separately
    end # end for loop

    # Save 3D image
    Makie.save("final.png",scene)

    # Make movie
    FFMPEG.exe("options for movie")
end # end isosurface3D()

Makie actually uses FFMPEG internally for animations, and we’ve built in a bunch of optimizations throughout the pipeline to make recording fast. On the latest version of AbstractPlotting.jl (Makie is the metapackage, AbstractPlotting is the bulk of the plotting code):

function isosurface3D(data,timeend)
    scene = volume(data[:,:,:,1],algorithm=:iso)
    volumeplot = scene.plots[end] # the last plot plotted to the Scene.
    record(scene, "movie.mp4", 1:timeend; framerate = 30) do i
        volumeplot[4][] = data[:, :, :, i] # update the data of the plot
    end # end recording loop

    # Save 3D image
    Makie.save("final.png",scene)

end # end isosurface3D()

and you’re done! If you want, you can also pass sleep = false as a keyword argument to record, to make it record as fast as possible. If you don’t pass it, the animation will be shown on the screen in real-time.

You should also take a look at http://makie.juliaplots.org/dev/animation.html and http://makie.juliaplots.org/dev/interaction.html, which have some more info about using Observables.

Let me know if you have any questions!

4 Likes