JMF massive memory leak

Discussion in 'Java' started by wish, Apr 30, 2005.

  1. wish

    wish Guest

    Hi,

    i'm trying to build a simple app using tutorial based player, that would
    display a couple of videos at a time in a paused state showing the first
    frame of each of them.

    This gives me a headache, because calling start() on a player and stop()
    directly after its realisation seems to make its resources impossible to
    destroy. The effect is, that after refreshing the screen 3 times with 12
    thumbnails on it my program is occupying over 200 MB of memory :).

    I've noticed that simple calling start(), playing and then destroying player
    as it is said in all documentation works well. Perhaps there is some
    timeline in which methods, garbage collector and other stuff should be
    called in order to close everything properly? I've gone through every
    possible newsgroup and can't find the answer.

    Here is a code sample from my player class. I'd be grateful for any help on
    this.

    Thx.




    public class VideoComponent extends JPanel implements ControllerListener {


    [.........Cut..........]


    // ------------------------------------------------------------------------
    public void init() {
    MediaLocator mrl;
    URL url;
    File file;

    this.setOpaque(false);
    this.setLayout(new BorderLayout());
    this.setBackground(Color.black);
    panel = new JPanel();
    panel.setOpaque(false);
    panel.setLayout(new BorderLayout());
    this.add(panel, BorderLayout.CENTER);

    try {
    file = new File(videoPath);
    url = new URL("file:///" + file.getAbsolutePath());
    mrl = new MediaLocator(url);

    // jesli nie ma pliku wywal blad
    if (mrl == null) error("No media locator");


    try {
    player = Manager.createPlayer(mrl);
    } catch (Exception e) {
    e.printStackTrace();
    error(e.getMessage());
    }

    /* dodaj ta klase jako listener playera */
    player.addControllerListener(this);

    } catch (MalformedURLException e) {
    error("Invalid media file URL!");
    } catch (IOException e) {
    error("IO exception creating player");
    }

    start();
    }


    // ------------------------------------------------------------------------
    public void start() {
    if (player == null) return;
    player.start();
    playing = true;
    }


    // ------------------------------------------------------------------------
    public void stop() {
    if (player != null) {
    player.stop();
    player.deallocate();

    }
    playing = false;
    }


    // ------------------------------------------------------------------------
    public void pause() {
    if (player != null) player.stop();
    playing = false;
    }


    // ------------------------------------------------------------------------
    public void destroy() {
    if (player != null) player.close();
    playing = false;
    }


    // ------------------------------------------------------------------------
    private void removeView() {
    panel.removeAll();
    controlComponent.dispose();
    visualComponent = null;
    controlComponent = null;
    }


    // ------------------------------------------------------------------------
    private void removePlayer() {
    player.removeControllerListener ( this );
    player = null;
    }


    // ------------------------------------------------------------------------
    public synchronized void controllerUpdate(ControllerEvent event) {

    [.........Cut..........]

    if (event instanceof RealizeCompleteEvent) {

    if (!autoPlay) pause();

    [.........Cut..........]


    } else if (event instanceof EndOfMediaEvent) {

    if (!loop) return;
    player.setMediaTime(new Time(0));
    player.start();

    } else if (event instanceof ControllerErrorEvent) {
    stop();
    destroy();
    error(event.toString());
    } else if (event instanceof ControllerClosedEvent) {
    removeView();
    removePlayer();
    }

    }


    // ------------------------------------------------------------------------
    private void error(String msg) {
    System.out.println(msg);
    }



    }
     
    wish, Apr 30, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CMan

    JMF Memory leak

    CMan, Sep 4, 2003, in forum: Java
    Replies:
    1
    Views:
    532
    Robert Olofsson
    Sep 4, 2003
  2. Replies:
    1
    Views:
    777
    Andrew Thompson
    Jul 20, 2006
  3. Hallvard B Furuseth

    slowdown with massive memory usage

    Hallvard B Furuseth, Jul 30, 2004, in forum: Python
    Replies:
    5
    Views:
    331
    Bengt Richter
    Aug 1, 2004
  4. Cyhawk

    Question about massive arrays and memory

    Cyhawk, Nov 1, 2005, in forum: C Programming
    Replies:
    2
    Views:
    337
    Malcolm
    Nov 1, 2005
  5. Replies:
    0
    Views:
    2,404
Loading...

Share This Page