JavaFX - 对象卡在内存中

时间:2017-08-09 17:17:56

标签: java javafx-2

我有一个使用import React, { Component } from 'react'; import { View, StyleSheet,Platform,Button } from 'react-native'; export default class App extends Component { state = { isSelected: false } render() { return ( <View style={styles.container}> <View style={this.state.isSelected ? styles.boxSelected : styles.boxUnselected} ></View> <Button title='toggle select' onPress={() => this.setState({isSelected: !this.state.isSelected}) } /> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: '#ecf0f1', }, boxSelected: { width:100, height:100, backgroundColor:'blue', borderRadius:10, ...Platform.select({ ios: { shadowColor: 'rgba(0,0,0, .7)', shadowOffset: { height:0, width: 0 }, shadowOpacity: 1, shadowRadius: 5, }, android: { elevation: 5 }, }), }, boxUnselected: { width:100, height:100, backgroundColor:'blue', borderRadius:10, } }); 构建的庞大应用程序,因为有很多阶段要显示我创建了一个类来加载视图[更像是utils类],称为JavaFX(我认为问题是,)为了显示单个阶段我应该创建一个FXMLManager的实例,在阶段关闭后FXMLManager实例保留在内存中,我尝试将对象设置为null后舞台关闭,没有运气..

FXMLManager

FXMLManager.java

我正在使用public class FXMLManager<T extends AbstractController> { /** * */ private static ClassLoader cachingClassLoader = new FXMLlightweightLoader(FXMLLoader.getDefaultClassLoader()); private final Class<T> clazzType; @Getter private T controller; private FXMLLoader fxmlLoader; @Getter private Parent root; public FXMLManager(Class<T> clazz) { this.clazzType = clazz; Annotation annotation = this.clazzType.getAnnotation(FXMLController.class); if (annotation == null) throw new NullPointerException( "controller type provided is not annotated with FXMLController : " + clazzType); FXMLController fxmlController = (FXMLController) annotation; this.fxmlLoader = constructFXMLLoader(); this.fxmlLoader.setLocation(getURL(fxmlController.value())); try { AbstractController abstractController = (AbstractController) clazzType.newInstance(); this.fxmlLoader.setController(abstractController); this.root = (Parent) this.fxmlLoader.load(); } catch (Exception e) { e.printStackTrace(); } this.controller = this.fxmlLoader.getController(); } private FXMLLoader constructFXMLLoader() { FXMLLoader fxmlLoader = new FXMLLoader(); fxmlLoader.setClassLoader(cachingClassLoader); fxmlLoader.setResources(I18NSupport.getBundle()); return fxmlLoader; } public T getController(Class<T> controllerType) { T controller = controllerType.cast(this.fxmlLoader.getController()); return controller; } public static URL getURL(String url) { return FXMLManager.class.getResource(url); } private Stage stage; public Stage getStage(String title) { if (stage == null) { Scene scene = new Scene(this.root); stage = new Stage(); stage.initModality(Modality.APPLICATION_MODAL); stage.setResizable(false); stage.setScene(scene); stage.getIcons().add(ImageLoader.loadImage("icon")); } stage.setTitle(title); return stage; } } ,如下所示:

FXMLManager

我做错了吗?据我所知public static void openRandomForm() { FXMLManager<Controller> fxmlManager = new FXMLManager<>(Controller.class); //fxmlManager.getController(); do stuff with the controller Stage stage = fxmlManager.getStage("title"); stage.showAndWait(); fxmlManager = null; } 应该被清除,不是吗? 在显示几个阶段然后执行FXMLManager之后,堆转储的屏幕截图: enter image description here enter image description here

0 个答案:

没有答案