Java 计时器内存不足异常

Java 计时器内存不足异常,java,timer,Java,Timer,我有一个大问题,我正在使用对象的arraylist,这个对象内部有一个计时器。 所以我用10作为计时器,所以arraylist的长度是10 整个计时器几乎占用内存80 MB。。如果我使用我的程序一点时间,程序会给我内存不足的异常 因为所有的计时器都会占用大量内存,如果我从一帧移动到另一帧 另一帧,程序占用相同的内存量 我希望如果我尝试取消所有计时器或将对象设置为null 内存将减少,但不起作用 如果问题不清楚,请在评论中提问 对不起,我的英语不好 注: 这个程序很简单,但真正的程序很大 我的对象

我有一个大问题,我正在使用对象的arraylist,这个对象内部有一个计时器。 所以我用10作为计时器,所以arraylist的长度是10

整个计时器几乎占用内存80 MB。。如果我使用我的程序一点时间,程序会给我内存不足的异常

因为所有的计时器都会占用大量内存,如果我从一帧移动到另一帧

另一帧,程序占用相同的内存量

我希望如果我尝试取消所有计时器或将对象设置为null

内存将减少,但不起作用

如果问题不清楚,请在评论中提问

对不起,我的英语不好

注:

这个程序很简单,但真正的程序很大

我的对象(边缘):

package operationresearch.pert.input;
导入java.util.ArrayList;
导入java.util.Timer;
导入java.util.TimerTask;
导入javafx.geometry.Insets;
导入javafx.scene.control.Label;
导入javafx.scene.control.TextField;
导入javafx.scene.effect.Bloom;
导入javafx.scene.input.MouseEvent;
导入javafx.scene.layout.HBox;
公共类边缘扩展HBox{
私人ArrayList前身;
专用定时器t2;
私有文本字段持续时间、活动;
公共边缘(布尔时间){
前置项=新的ArrayList();
活动=新文本字段();
活动大小(80,25);
活动。SetPrompText(“活动”);
如果(有时间){
持续时间=新文本字段();
持续时间.setPrefSize(85,25);
持续时间。SetPrompText(“持续时间”);
}
标签依赖=新标签(“依赖”);
depend.setEffect(newbloom());
TextField init=新的TextField();
初始setPrefSize(40,20);
添加(init);
这是第5步;
如果(有时间){
this.getChildren().addAll(活动、持续时间、依赖、初始化);
}否则{
this.getChildren().addAll(活动、依赖、初始化);
}
设置填充(新插入(0,30,0,0));
前置控制();
}
私有无效先人控制(){
t2=新定时器();
TimerTask2=新的TimerTask(){
@凌驾
公开募捐{
TextField last=preducer.get(preducer.size()-1);
last.setOnMouseClicked((MouseeEvent e)->{
if(last==preference.get(preference.size()-1)){
TextField newText=新TextField();
newText.setPrefSize(50,20);
添加(新文本);
getChildren().add(newText);
}
对于(int i=0;i
}

主要内容:

package javaapplication2;

import java.util.ArrayList;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;



    public class TestApp3 extends Application {

        private ArrayList<edge> graph;

        public static void main(String[] args) {
            launch(args);
        }

        @Override 

    public void start(Stage stage) throws Exception {
        VBox root = new VBox();
        graph = new ArrayList();

        for (int i = 0; i < 10; i++) {
            edge edge = new edge(true);
            graph.add(edge);
            root.getChildren().add(edge);
        }

        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setWidth(500);
        stage.setHeight(500);
        stage.show();
    }
}
PackageJavaApplication2;
导入java.util.ArrayList;
导入javafx.application.application;
导入javafx.scene.scene;
导入javafx.scene.layout.Pane;
导入javafx.scene.layout.VBox;
导入javafx.stage.stage;
公共类TestApp3扩展了应用程序{
私有数组列表图;
公共静态void main(字符串[]args){
发射(args);
}
@凌驾
public void start(Stage)引发异常{
VBox root=新的VBox();
graph=新的ArrayList();
对于(int i=0;i<10;i++){
边缘=新边缘(真);
添加(边);
root.getChildren().add(边缘);
}
场景=新场景(根);
舞台场景;
舞台设置宽度(500);
舞台设置高度(500);
stage.show();
}
}

为什么你要描述你的代码而不是发布它?对不起,我要让你edit@shmosel现在,通过在任务管理器中查看流程,您可以看到我的问题。您为什么要描述代码而不是发布代码?对不起,我要edit@shmosel现在,通过在任务管理器中查看流程,您可以看到我的问题
package javaapplication2;

import java.util.ArrayList;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;



    public class TestApp3 extends Application {

        private ArrayList<edge> graph;

        public static void main(String[] args) {
            launch(args);
        }

        @Override 

    public void start(Stage stage) throws Exception {
        VBox root = new VBox();
        graph = new ArrayList();

        for (int i = 0; i < 10; i++) {
            edge edge = new edge(true);
            graph.add(edge);
            root.getChildren().add(edge);
        }

        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setWidth(500);
        stage.setHeight(500);
        stage.show();
    }
}