dispose() method in GLVideo

edited November 2016 in Raspberry PI

hi all, i'd like to pick video clips randomly from within draw(). tried to use dispose() to free memory, but it didn't seem to work.

`movie.dispose();
 movie = new GLMovie(this, "foo.mp4");
 movie.loop();`

any advice? thanks

Tagged:

Answers

  • What's the exact issue you're seeing?

    Generally it's probably not a good idea to load a video clip inside draw. I'd consider having an array of GLMovie objects, instantiating them all in setup, and calling play or loop at them - one at a time - inside draw. When the clip is no longer used you could try to call movie.stop(), movie.close().

    You could try to also set movie = NULL and afterwards force garbage collection with System.gc() - but that's a bit of black magic I don't know much myself.

    Let us know what worked in the end!

  • edited November 2016
    • @gohai, @codo's excerpt should work the very way it was typed in.
    • Variable movie is assigned to another GLMovie instance after invoking dispose() over the old 1.
    • Method dispose() is just an alias for method close().
    • Which in turn calls native gstreamer_close() method.
    • In short, it shouldn't have any memory leak issues there!
    • Btw, the movie = null; "obligatory" step is bullocks superstition! And it's null, not NULL.
    • There's no method called stop() either.
  • edited November 2016
    • @codo, loading any resources after setup() is done is very tricky. =;
    • B/c by default draw() is continuously called back at about 60 FPS! @-)
    • So you've gotta check whether some resource had already been loaded in order to avoid reloading it again and again! :-SS
    • Take notice that any resource loading slows down draw() considerably.
    • A more efficient approach is having some separate thread() method to deal w/ any loading tasks.
    • In general, if you can afford (got enough memory), load all resources before draw() starts in order to avoid all such headaches! ~X(
  • @GoToLoop I was suggesting an array of instances - in this case you might actually want to destroy one by setting it to null, no superstition. dispose() is an internal, undocumented method. And yes, pause().

  • edited November 2016

    I was suggesting an array of instances...

    If we're filling up that array at setup(), the best approach is pause() a GLMovie rather than dispose() & null it.

    What I ranted about was the superstition case below:

    movie.dispose();
    movie = null; // <- stupid superstious redundancy!!!
    movie = new GLMovie(this, "foo.mp4");
    movie.loop();
    

    Given variable movie was about to get assigned another instance right way, assigning it to null 1st was dumb! :O)

    dispose() is an internal, undocumented method.

    Your library seems to follow the API names from Processing's Video library. Am I right?
    https://Processing.org/reference/libraries/video/index.html

    • There's no method called close() there but dispose().
    • While your library got both close() & dispose() methods.
    • And dispose() is just an alias for close().
    • For familiarity's sake, you should elevate dispose() as the main 1 instead!
    • In relation to "internal", "undocumented" classification I ask:
    • How is any1 supposed to get rid of an instance of GLMovie w/o 1st calling dispose() or close() over it??? 3:-O
    • Given hardware resources are native. And Java's GC can't deallocate something written in another language!
    • Reassigning a variable to something else would only destroy the Java object.
    • But the hardware resource would still live on, causing serious memory leakage & CPU hogging! X(
  • @gohai@GoToLoop thanks for your input! the issues i see are related to gpu memory. for the moment i test with a total of four .mp4 video snippets, ~ 2.5mb each. i think, when instantiating them within setup(), they immediately want to live in gpu ram. i'm on rpi3, so i got ~1000mb. i dedicated 256mb to gpu to get rid of memory related errors. then i tried the dynamic loading/disposing thing from within draw(). it works, but i have no idea for how long because: during runtime i keep an eye on taskmanager. there are two tasks named "java". i think they both live in gpu ram and both tend to grow. (the one i suspect to hold the sketch goes over 80mb, just by loading/disposing a total of 10mb of .mp4's.) in the end i want to use ~100mb of snippets which only makes sense with some sort of dispose thing.

    i've put the load/dispose part in an extra thread now. working!.

    i have to think about an array, but i don't want to call snippets by filename. just put them all in a folder and pick randomly by something like "*.mp4"!?


  • @GoToLoop Please rethink the language you use in the forum. It's not useful to label other people's suggestion as stupid, or dumb. (Just makes me want to not spend any more time in this forum.)

    If you had actually taken the time to read my initial comment, you would have understood my proposed sequence as:

    movie[cur+1].play();
    movie[cur].pause();
    movie[cur].close();
    movie[cur] = null;
    System.gc();
    

    What here is stupid superstitious redundancy?

  • edited November 2016

    I gave an example pinpointing exactly what I meant by my generic rant.
    Which obviously wasn't your case, @gohai! Sorry about that! X_X

    About your last example above, it presumes the array was fill up w/ instances of GLMovie within setup().
    It also presumes that the sketch had that much RAM available.
    Therefore I don't see much logic to dispose()/close() any of those GLMovie later in draw().
    Just a simple pause() will do. Later on, if that same GLMovie is needed again, just call play() for it.

    If some1 can't afford to load all those GLMovie files, or just wanna keep the RAM usage low, it needs to constantly dispose() a GLMovie before loading a new 1. :-B

Sign In or Register to comment.