{"action":"created","issue":{"url":"https://api.github.com/repos/sialcasa/mvvmFX/issues/429","repository_url":"https://api.github.com/repos/sialcasa/mvvmFX","labels_url":"https://api.github.com/repos/sialcasa/mvvmFX/issues/429/labels{/name}","comments_url":"https://api.github.com/repos/sialcasa/mvvmFX/issues/429/comments","events_url":"https://api.github.com/repos/sialcasa/mvvmFX/issues/429/events","html_url":"https://github.com/sialcasa/mvvmFX/issues/429","id":170360217,"number":429,"title":"Controller/CodeBehind gets garbage collected when View is loaded with FluentViewLoader","user":{"login":"maimArt","id":20232625,"avatar_url":"https://avatars.githubusercontent.com/u/20232625?v=3","gravatar_id":"","url":"https://api.github.com/users/maimArt","html_url":"https://github.com/maimArt","followers_url":"https://api.github.com/users/maimArt/followers","following_url":"https://api.github.com/users/maimArt/following{/other_user}","gists_url":"https://api.github.com/users/maimArt/gists{/gist_id}","starred_url":"https://api.github.com/users/maimArt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maimArt/subscriptions","organizations_url":"https://api.github.com/users/maimArt/orgs","repos_url":"https://api.github.com/users/maimArt/repos","events_url":"https://api.github.com/users/maimArt/events{/privacy}","received_events_url":"https://api.github.com/users/maimArt/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-08-10T08:25:51Z","updated_at":"2016-09-20T06:51:22Z","closed_at":"2016-08-10T11:58:15Z","body":"Hi,\r\n\r\nin our project we dynamically change the center content of our view.\r\n\r\nSo i am doing stuff like:\r\n`ViewTuple centerViewTuple= fluentViewLoader.fxmlView(viewType).load(); \r\n`\r\n`centerPane.getChildren().clear(); `\r\n`centerPane.getChildren().add(centerViewTuple.getView()); `\r\n\r\nIf i load the view like that without explicitly holding a reference to its code behind the controller/codeBehind will be garbage collected immediatly.\r\nOf course if i add a strong reference of the controller to the viewmodel by adding a listener to a property of the viewmodel for example, the controller will also not be garbage collected.\r\nBut if i only use weak bindings like in most mvvm use cases the controller will be garbage collected if i don´t explicitly hold a reference to it like that:\r\n\r\n`private ViewTuple centerViewTuple;`\r\n\r\n`private void xyz(Class<? extends FxmlView> viewType){`\r\n`centerViewTuple= fluentViewLoader.fxmlView(viewType).load(); \r\n`\r\n`centerPane.getChildren().clear(); `\r\n`centerPane.getChildren().add(centerViewTuple.getView()); `\r\n`}`\r\nI am not sure if it is a general problem of the javafx framework but i spent some time to find the failure So possibly other guys will fall over the same pitfall and you could mention this behaviour in your documentation.\r\n\r\nGreets from Munich"},"comment":{"url":"https://api.github.com/repos/sialcasa/mvvmFX/issues/comments/248217948","html_url":"https://github.com/sialcasa/mvvmFX/issues/429#issuecomment-248217948","issue_url":"https://api.github.com/repos/sialcasa/mvvmFX/issues/429","id":248217948,"user":{"login":"lestard","id":328387,"avatar_url":"https://avatars.githubusercontent.com/u/328387?v=3","gravatar_id":"","url":"https://api.github.com/users/lestard","html_url":"https://github.com/lestard","followers_url":"https://api.github.com/users/lestard/followers","following_url":"https://api.github.com/users/lestard/following{/other_user}","gists_url":"https://api.github.com/users/lestard/gists{/gist_id}","starred_url":"https://api.github.com/users/lestard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lestard/subscriptions","organizations_url":"https://api.github.com/users/lestard/orgs","repos_url":"https://api.github.com/users/lestard/repos","events_url":"https://api.github.com/users/lestard/events{/privacy}","received_events_url":"https://api.github.com/users/lestard/received_events","type":"User","site_admin":false},"created_at":"2016-09-20T06:51:22Z","updated_at":"2016-09-20T06:51:22Z","body":"Hi emcastro,\r\nyour solution prevents the GC as well. \r\nHowever, it's not so easy when you have embedded FXML files. \r\n\r\nIn this case you need to set an `fx:id` on the root element in the FXML file, \r\ninject a reference to the root node in your controller class and write `root.setUserData(this)` in the initialize method (therefore `this` points to the actual instance of the controller). \r\nThis should work but it's not obvious for other developers why this is done in the code. It's not really descriptive. \r\nA marker interface with a descriptive name could be beneficial in such situations."}}
{"actor":{"display_login":"lestard"}}