0

我无法解决问题,需要您的帮助。当我点击菜单时,我打电话给客户帐户,然后我关闭它。每次我打电话给客户帐户时,内存都会增加。当我关闭帐户时它应该会减少,但它不会发生。

班级菜单

mnItemCL_Cust.setOnAction(new EventHandler<ActionEvent>() {
  @Override
  public void handle(ActionEvent t) {
    try {
      panCenterPrev = (Pane) root.getCenter();
      panCenterAct = Customer.listCustomer();
      root.setCenter(null);
      root.setCenter(panCenterAct);
      Customer.btCanc.setOnAction(new EventHandler<ActionEvent>() {
        @Override public void handle(ActionEvent e) {
          try {
            Customer.Fim();
            panCenterAct.getChildren().clear();
            panCenterAct = null;
            root.setCenter(null);
            root.setCenter(panCenterPrev);
          } catch (Throwable ex) {
            Logger.getLogger(Customer.class.getName()).log(Level.SEVERE, null, ex);
          }
        }             
});

类客户

public class Customer
{

  public static Pane listCustomer() throws SQLException, ClassNotFoundException
  {
    ...
    final ObservableList<MyCustomer> data = FXCollections.observableArrayList();
    ...
  }

  public static class MyCustomer {
    private final SimpleIntegerProperty idcl;
    private MyCustomer(Integer pIdcl ) {
      this.idcl = new SimpleIntegerProperty(pIdcl);  
    }

    public Integer getIdcl() {
         return idcl.get();
    }

    public void setIdcl(Integer pIdcl) {
        idcl.set(pIdcl);
    }
  }  

  public static void Fim() throws Throwable {
    ...
    rs = null;

    tbViewCL.getItems().clear();
    tbViewCL = null;
    colIDCL.getColumns().clear();
    colIDCL = null;
  }

  ...

  protected void finalize() throws Throwable {
    try{
      ...
      rs.close();
      ...// Never happens... why??  
    } catch(Throwable t) {
        throw t;
    } finally {
        JOptionPane.showMessageDialog(null,"End?");
        super.finalize();
    }
  }

问候

4

1 回答 1

0

Java 通常会在它认为合适时回收您使用的内存,因此即使您最终确定了对象,内存可能仍然存在。但是,如果rs.Close()从不执行,可能是因为在它抛出和异常之前的某些东西,我建议您在之前检查代码以确保没有这样做,此外,如果您捕获异常是记录它的好习惯所以你可以知道发生了什么。

于 2012-11-16T21:00:37.387 回答