|  | <html> | 
|  |  | 
|  | <head> | 
|  | <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> | 
|  | <meta name="GENERATOR" content="Microsoft FrontPage 4.0"> | 
|  | <meta name="ProgId" content="FrontPage.Editor.Document"> | 
|  | <title>LeakExample.java</title> | 
|  | </head> | 
|  |  | 
|  | <body> | 
|  |  | 
|  | <b> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><font COLOR="#7f0055">import </font></b>org.eclipse.swt.*;</p> | 
|  | <b> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><font COLOR="#7f0055">import </font></b>org.eclipse.swt.graphics.*;</p> | 
|  | <b> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><font COLOR="#7f0055">import </font></b>org.eclipse.swt.widgets.*;</p> | 
|  | <b> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><font COLOR="#7f0055">import </font></b>org.eclipse.swt.events.*;</p> | 
|  | <b> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><font COLOR="#7f0055">import </font></b>org.eclipse.swt.layout.*;</p> | 
|  | <b> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><font COLOR="#7f0055">import </font></b>org.eclipse.swt.program.*;</p> | 
|  | <b> | 
|  | <p style="margin-top: 0; margin-bottom: 0"> </p> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><font COLOR="#7f0055">public class </font></b>LeakExample | 
|  | {</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><b><font COLOR="#7f0055">    | 
|  | static </font></b>Display display;</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><b><font COLOR="#7f0055">    | 
|  | static </font></b>Shell shell;</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><b><font COLOR="#7f0055">    | 
|  | static </font></b>List list;</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><b><font COLOR="#7f0055">    | 
|  | static </font></b>Canvas canvas;</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><b><font COLOR="#7f0055">    | 
|  | static </font></b>Image image;</p> | 
|  | <font SIZE="2"> | 
|  | <p style="margin-top: 0; margin-bottom: 0"> </p> | 
|  | </font><b> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><font COLOR="#7f0055">public static | 
|  | void </font></b>main(String[] args) {</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><font color="#3F7F5F">    | 
|  | // DeviceData data = <b>new </b>DeviceData();</font></p> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><font color="#3F7F5F">    | 
|  | // data.tracking = <b>true</b>;</font></p> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><font color="#3F7F5F">    | 
|  | // display = <b>new </b>Display(data);</font></p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">    display = <b><font COLOR="#7f0055">new | 
|  | </font></b>Display();</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><font COLOR="#3f7f5f">    | 
|  | // Sleak sleak = new Sleak();</font></p> | 
|  | <font SIZE="2"> | 
|  | <p style="margin-top: 0; margin-bottom: 0"></font><font COLOR="#3f7f5f">    | 
|  | // sleak.open();</font></p> | 
|  | <p style="margin-top: 0; margin-bottom: 0"> </p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">    shell = <b><font COLOR="#7f0055">new | 
|  | </font></b>Shell(display);</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">    shell.setLayout(<b><font COLOR="#7f0055">new | 
|  | </font></b>FillLayout());</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">    list = <b><font COLOR="#7f0055">new | 
|  | </font></b>List(shell, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL);</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">    | 
|  | list.setItems(Program.getExtensions());</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">    canvas = <b><font COLOR="#7f0055">new | 
|  | </font></b>Canvas(shell, SWT.BORDER);</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">    | 
|  | canvas.addPaintListener(<b><font COLOR="#7f0055">new </font></b>PaintListener() | 
|  | {</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><b><font COLOR="#7f0055">        | 
|  | public void </font></b>paintControl(PaintEvent e) {</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><b><font COLOR="#7f0055">            | 
|  | if </font></b>(image != <b><font COLOR="#7f0055">null</font></b>) {</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">                | 
|  | e.gc.drawImage(image, 0, 0);</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">            | 
|  | }</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">        | 
|  | }</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">    });</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">    | 
|  | list.addSelectionListener(<b><font COLOR="#7f0055">new </font></b>SelectionAdapter() | 
|  | {</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><b><font COLOR="#7f0055">        | 
|  | public void </font></b>widgetSelected(SelectionEvent e) {</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">            | 
|  | image = <b><font COLOR="#7f0055">null</font></b>; <font color="#3F7F5F"> | 
|  | // potentially leak one image </font></p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">            | 
|  | String[] selection = list.getSelection();</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><b><font COLOR="#7f0055">            | 
|  | if </font></b>(selection.length != 0) {</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">                | 
|  | Program program = Program.findProgram(selection[0]);</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><b><font COLOR="#7f0055">                | 
|  | if </font></b>(program != <b><font COLOR="#7f0055">null</font></b>) {</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">                    | 
|  | ImageData imageData = program.getImageData();</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><b><font COLOR="#7f0055">                    | 
|  | if </font></b>(imageData != <b><font COLOR="#7f0055">null</font></b>) {</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">                        | 
|  | <b><font COLOR="#7f0055">if </font></b>(image != <b><font COLOR="#7f0055">null</font></b>) | 
|  | image.dispose();</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">                        | 
|  | image = <b><font COLOR="#7f0055">new </font></b>Image(display, imageData);</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">                    | 
|  | }</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">                | 
|  | }</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">            | 
|  | }</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">            | 
|  | canvas.redraw();</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">        | 
|  | }</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">    });</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">    | 
|  | shell.setSize(shell.computeSize(SWT.DEFAULT, 200));</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">    shell.open();</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><b><font COLOR="#7f0055">    | 
|  | while </font></b>(!shell.isDisposed()) {</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0"><b><font COLOR="#7f0055">    | 
|  | if </font></b>(!display.readAndDispatch()) display.sleep();</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">    }</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">}</p> | 
|  | <p style="margin-top: 0; margin-bottom: 0">}</p> | 
|  |  | 
|  | </body> | 
|  |  | 
|  | </html> |