Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23
  1. #21
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,998
    Rep Power
    5

    Default Re: JavaFx and memory consumption

    I wanted to see that JVisualVM was used to examine the heap; the task manager is useless to know how much memory your application is effectively using, it only shows how much memory the Java process has claimed in total - for itself and the total heap. If that shows 1gb, that does not mean that the application is actually using 1gb, it only means it used something close to 1gb at some point in time which triggered the JVM to grow the heap to that size.

    I may be blind, but the heap usage in the JVisualVM screenshots looks quite alright. There are quite a few threads indeed, it seems something is still leaky there. You might want to ask about that in the OTN forums. It used to be that the JavaFX devs were also looking there when it was newly released, I don't know if that is still true.

    https://community.oracle.com/communi..._2.0_and_later
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  2. #22
    Kyuzo is offline Member
    Join Date
    Apr 2014
    Posts
    11
    Rep Power
    0

    Default Re: JavaFx and memory consumption

    Quote Originally Posted by Tolls View Post
    OK.
    So giving it a bigger screen increases the memory usage. No surprise there (IMO).

    The thread increase may be related to that.
    How long are the videos, on average?

    Also, what time did the videos start playing?
    17:00 or earlier? Just trying to see if the thread increase is something that occurs straight away, or something that takes time to build up.
    In the screen there is "Uptime" that indicates the exact time of execution of the software.
    Also, as you can see from the screen that I did on my computer (attached), the program behavior is different.


    Quote Originally Posted by gimbal2 View Post
    I wanted to see that JVisualVM was used to examine the heap; the task manager is useless to know how much memory your application is effectively using, it only shows how much memory the Java process has claimed in total - for itself and the total heap. If that shows 1gb, that does not mean that the application is actually using 1gb, it only means it used something close to 1gb at some point in time which triggered the JVM to grow the heap to that size.

    I may be blind, but the heap usage in the JVisualVM screenshots looks quite alright. There are quite a few threads indeed, it seems something is still leaky there. You might want to ask about that in the OTN forums. It used to be that the JavaFX devs were also looking there when it was newly released, I don't know if that is still true.

    https://community.oracle.com/communi..._2.0_and_later
    I used VisualVM ( Home — Project Kenai )
    The heap usage is OK.
    however, the program freezes after two hours.

    To integrate javafx in swing use this code :

    Java FX Code:
    final JFXPanel fxPanel = new JFXPanel();
    		
    		this.setLayout(null);
    		this.add(fxPanel);
    		this.add(south);
    
    		this.setSize(xSize,ySize); 
    		this.setUndecorated(true);		  	   
    		this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    
    
    		
    		Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    // This method is invoked on JavaFX thread
                	Scene scene = new SceneGenerator(xSize,ySize).createScene();
            		fxPanel.setScene(scene);
                }
            });
    But reading this article ( JavaFX - APIDesign ) I understand that the algorithm is obsolete.
    It does not quite find what is the algorithm that improves the integration of javafx and swing without using separate threads.
    Attached Files Attached Files

  3. #23
    Kyuzo is offline Member
    Join Date
    Apr 2014
    Posts
    11
    Rep Power
    0

    Default Re: JavaFx and memory consumption

    I find this page ( https://javafx-jira.kenai.com/browse/RT-28379 ). the problem seems to know or not?
    anyway, I tried to change the code in this way, but the problem remains:

    Java FX Code:
    package application;
    
    import java.io.File;
    import java.io.FilenameFilter;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.List;
    
    import javax.swing.JOptionPane;
    
    import javafx.application.Platform;
    import javafx.geometry.Pos;
    import javafx.scene.Scene;
    import javafx.scene.layout.StackPane;
    import javafx.scene.layout.VBox;
    import javafx.scene.media.MediaView;
    import javafx.scene.media.MediaPlayer;
    import javafx.scene.media.Media;
    
    
    
    class SceneGenerator {    
    
    	private int xSize;
    	private int ySize;
    	private MediaPlayer playerNew;
    
    	private int nextFileIndex = -1 ;
    	//	private static ThreadChange createPlayerThread = new ThreadChange();	
    	private List<String> videoFiles;
    	private MediaView mediaView;
    	//	private boolean first=true;
    	private final Runnable finale;
    	private boolean first=true;
    
    	public SceneGenerator(int xSize,int ySize){
    		this.xSize=xSize;
    		this.ySize=ySize;
    
    		finale = new Runnable() {
    			@Override
    			public void run() {
    
    
    				esegui();
    
    			}
    		};
    	}
    	public Scene createScene() { 
    		final StackPane layout = new StackPane();
    		// determine the source directory for the playlist
    		final File dir = new File(System.getProperty("user.dir")+"//video");
    		if (!dir.exists() || !dir.isDirectory()) {
    			JOptionPane.showMessageDialog(null,"Cannot find video source directory: " + dir);
    			Platform.exit();
    			System.exit(0);
    			return null;
    		}
    
    		//inizializzo il toolkit
    
    
    		mediaView = new MediaView();
    
    		mediaView.setPreserveRatio(false);
    		mediaView.setFitHeight(ySize-((ySize/100)*(JavaPlayer.panelSouthYDimension+1)-JavaPlayer.pixelAdattamento));
    		mediaView.setFitWidth(xSize);
    
    		videoFiles = new ArrayList<String>();
    		for (String file : dir.list(new FilenameFilter() {
    			@Override public boolean accept(File dir, String name) {
    				return name.endsWith(".mp4")||name.endsWith(".flv");
    			}
    		})) videoFiles.add("file:///" + (dir + "/" + file).replace("\\", "/"));
    		Collections.sort(videoFiles);
    		
    
    		esegui();
    
    		// layout the scene.
    		layout.setStyle("-fx-background-color: black; -fx-font-size: 20; -fx-padding: 0; -fx-alignment: center;");
    		VBox vBox = new VBox();
    		vBox.setAlignment(Pos.CENTER);
    		vBox.getChildren().add(mediaView);
    		layout.getChildren().addAll(vBox);
    
    		return new Scene(layout);
    	}
    
    	public void esegui(){
    
    
    		nextFileIndex = (nextFileIndex + 1) % videoFiles.size();
    
    		
    		if(first==false){
    			
    			playerNew.stop();
    			
    			playerNew.dispose();
    			
    			playerNew = null;
    			
    			mediaView.setMediaPlayer(null);
    			
    			System.gc();
    		
    			
    		}
    		else{
    			first=false;
    		}
    		
    
    
    		playerNew = new MediaPlayer(new Media(videoFiles.get(nextFileIndex).toString()));
    
    
    		mediaView.setMediaPlayer(playerNew);
    
    
    		playerNew.play();
    
    
    		playerNew.setOnEndOfMedia(finale);
    
    
    	}
    	
    
    }

Page 2 of 2 FirstFirst 12

Similar Threads

  1. How to reduce memory consumption in Java Desktop?
    By fanjavaid in forum Advanced Java
    Replies: 16
    Last Post: 07-19-2013, 04:59 AM
  2. JavaFX Book | Learn JavaFX More In Depth
    By SnakeDoc in forum JavaFX
    Replies: 0
    Last Post: 05-17-2013, 11:10 PM
  3. how to record maximum heap memory consumption
    By pvh35 in forum Advanced Java
    Replies: 2
    Last Post: 01-17-2011, 05:23 PM
  4. JavaFX Script and JavaFX Mobile
    By levent in forum Java Software
    Replies: 1
    Last Post: 01-27-2010, 04:48 PM
  5. Consumption of memory
    By Daniel in forum Advanced Java
    Replies: 1
    Last Post: 07-06-2007, 09:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •