Changeset 394 for trunk/loci/visbio/view


Ignore:
Timestamp:
05/12/05 15:57:18 (15 years ago)
Author:
curtis
Message:

Some work to try and make DisplayWindow, or at least its handlers, GC
properly when displays are removed. Doesn't work yet.

Location:
trunk/loci/visbio/view
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/visbio/view/DisplayControls.java

    r299 r394  
    153153    if (d == null) return; 
    154154    listModel.removeElement(d); 
    155     d.setVisible(false); 
    156     d.dispose(); 
     155 
     156    // remove display window from window manager 
     157    WindowManager wm = (WindowManager) 
     158      lm.getVisBio().getManager(WindowManager.class); 
     159    wm.disposeWindow(d); 
     160 
     161    // discard object 
     162    d.discard(); 
    157163  } 
    158164 
  • trunk/loci/visbio/view/DisplayWindow.java

    r373 r394  
    2626import java.awt.*; 
    2727import java.awt.event.*; 
     28import java.rmi.RemoteException; 
    2829import javax.swing.JFrame; 
    2930import javax.swing.JPanel; 
     
    317318      //controls.addKeyListener(this); 
    318319 
    319       // Note: adding the KeyListener directly to frames and panels is not 
     320      // NB: Adding the KeyListener directly to frames and panels is not 
    320321      // effective, because some child always has the keyboard focus and eats 
    321322      // the event. Better would be to add the keyboard listener to each 
     
    339340   * another object with a matching state. 
    340341   */ 
    341   public void discard() { } 
     342  public void discard() { 
     343    getContentPane().removeAll(); 
     344 
     345    // sever ties with un-GC-able display object 
     346    if (display != null) { 
     347      display.removeDisplayListener(this); 
     348      try { display.destroy(); } 
     349      catch (VisADException exc) { exc.printStackTrace(); } 
     350      catch (RemoteException exc) { exc.printStackTrace(); } 
     351      display = null; 
     352    } 
     353 
     354    // NB: Despite all of the above, ties are still not completely severed. 
     355    // VisADCanvasJ3D maintains a parent field (from the Canvas3D superclass) 
     356    // that points to this DisplayWindow. I am uncertain how to kill that 
     357    // reference, so instead we cut ties to a number of objects below. That 
     358    // way, though this DisplayWindow is not GCed, at least its constituent 
     359    // handlers are. 
     360    viewHandler = null; 
     361    captureHandler = null; 
     362    transformHandler = null; 
     363    sliders = null; 
     364    controls = null; 
     365    string = null; 
     366 
     367    // NB: And despite all of the fields nulled above, the handlers are also 
     368    // still not GCed. I do not understand why not. Frustrating. 
     369  } 
    342370 
    343371 
Note: See TracChangeset for help on using the changeset viewer.