pVarResult.dispose();
public Browser(Composite parent, int style) {	super(parent, style);	frame = new OleFrame(this, SWT.NONE);	try {		site = new WebSite(frame, SWT.NONE, "Shell.Explorer"); //$NON-NLS-1$	} catch (SWTException e) {		dispose();		SWT.error(SWT.ERROR_NO_HANDLES);	}	site.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);	auto = new OleAutomation(site);	addListener(SWT.Dispose, new Listener() {		public void handleEvent(Event e) {			if (auto != null)				auto.dispose();			auto = null;		}	});	addListener(SWT.Resize, new Listener() {		public void handleEvent(Event e) {			frame.setBounds(getClientArea());		}	});	OleListener listener = new OleListener() {		public void handleEvent(OleEvent event) {			switch (event.type) {				case BeforeNavigate2 : {					Variant varResult = event.arguments[0];					IDispatch dispatch = varResult.getDispatch();					Variant variant = new Variant(auto);					IDispatch top = variant.getDispatch();					if (top.getAddress() == dispatch.getAddress()) {						varResult = event.arguments[1];						String url = varResult.getString();						LocationEvent newEvent = new LocationEvent(Browser.this);						newEvent.display = getDisplay();						newEvent.widget = Browser.this;						newEvent.location = url;						for (int i = 0; i < locationListeners.length; i++)							locationListeners[i].changing(newEvent);						Variant cancel = event.arguments[6];						if (cancel != null) {							int pCancel = cancel.getByRef();							COM.MoveMemory(pCancel, new short[]{newEvent.cancel ? COM.VARIANT_TRUE : COM.VARIANT_FALSE}, 2);					   }					}										/*					* This code is intentionally commented.  This IDispatch was received					* as an argument from the OleEvent and it will be disposed along with					* the other arguments.  					*/					//dispatch.Release();					/*					* This code is intentionally commented.  A Variant constructed from an					* OleAutomation object does not increase its reference count.  The IDispatch					* obtained from this Variant did not increase the reference count for the					* OleAutomation instance either. 					*/					//top.Release();					//variant.dispose();					break;				}				case CommandStateChange : {					boolean enabled = false;					Variant varResult = event.arguments[0];					int command = varResult.getInt();					varResult = event.arguments[1];					enabled = varResult.getBoolean();					if (command == CSC_NAVIGATEBACK) backwardEnabled = enabled;					if (command == CSC_NAVIGATEFORWARD) forwardEnabled = enabled;					break;				}				case DocumentComplete: {					Variant varResult = event.arguments[0];					IDispatch dispatch = varResult.getDispatch();					Variant variant = new Variant(auto);					IDispatch top = variant.getDispatch();					if (top.getAddress() == dispatch.getAddress()) {						if (html != null) {							TCHAR buffer = new TCHAR(0, html, true);							html = null;							int byteCount = buffer.length() * TCHAR.sizeof;							int hGlobal = OS.GlobalAlloc(OS.GMEM_FIXED, byteCount);							if (hGlobal != 0) {								OS.MoveMemory(hGlobal, buffer, byteCount);								int[] ppstm = new int[1];								/* 								* Note.  CreateStreamOnHGlobal is called with the flag fDeleteOnRelease.								* If the call succeeds the buffer hGlobal is freed automatically								* when the IStream object is released. If the call fails, free the buffer								* hGlobal.								*/								if (OS.CreateStreamOnHGlobal(hGlobal, true, ppstm) == OS.S_OK) {									int[] rgdispid = auto.getIDsOfNames(new String[] {"Document"}); //$NON-NLS-1$									Variant pVarResult = auto.getProperty(rgdispid[0]);									IDispatch dispatchDocument = pVarResult.getDispatch();									pVarResult.dispose();									int[] ppvObject = new int[1];									int result = dispatchDocument.QueryInterface(COM.IIDIPersistStreamInit, ppvObject);									if (result == OS.S_OK) {										IPersistStreamInit persistStreamInit = new IPersistStreamInit(ppvObject[0]);										if (persistStreamInit.InitNew() == OS.S_OK) {											persistStreamInit.Load(ppstm[0]);										}										persistStreamInit.Release();									}									/*									* This code is intentionally commented.  The IDispatch obtained from a Variant									* did not increase the reference count for the enclosed interface.									*/									//dispatchDocument.Release();									IUnknown stream = new IUnknown(ppstm[0]);									stream.Release();								} else {									OS.GlobalFree(hGlobal);								}							}						} else {							varResult = event.arguments[1];							String url = varResult.getString();							LocationEvent locationEvent = new LocationEvent(Browser.this);							locationEvent.location = url;							for (int i = 0; i < locationListeners.length; i++)								locationListeners[i].changed(locationEvent);							ProgressEvent progressEvent = new ProgressEvent(Browser.this);							for (int i = 0; i < progressListeners.length; i++)								progressListeners[i].completed(progressEvent);						}					}										/*					* This code is intentionally commented.  A Variant constructed from an					* OleAutomation object does not increase its reference count.  The IDispatch					* obtained from this Variant did not increase the reference count for the					* OleAutomation instance either. 					*/					//top.Release();					//variant.dispose();											/*					* This code is intentionally commented.  This IDispatch was received					* as an argument from the OleEvent and it will be disposed along with					* the other arguments.  					*/					//dispatch.Release();					break;				}				case NewWindow2 : {					OpenWindowEvent openEvent = new OpenWindowEvent(Browser.this);					openEvent.display = getDisplay();					openEvent.widget = Browser.this;					for (int i = 0; i < openWindowListeners.length; i++)						openWindowListeners[i].open(openEvent);					Browser browser = openEvent.browser;					boolean doit = browser != null && !browser.isDisposed();					if (doit) {						Variant variant = new Variant(browser.auto);						IDispatch iDispatch = variant.getDispatch();						variant.dispose();						Variant ppDisp = event.arguments[0];						int byref = ppDisp.getByRef();						if (byref != 0) COM.MoveMemory(byref, new int[] {iDispatch.getAddress()}, 4);						iDispatch.Release();					}					Variant cancel = event.arguments[1];					int pCancel = cancel.getByRef();					COM.MoveMemory(pCancel, new short[]{doit ? COM.VARIANT_FALSE : COM.VARIANT_TRUE}, 2);					break;				}				case OnVisible : {					Variant arg1 = event.arguments[0];					boolean visible = arg1.getBoolean();					VisibilityEvent newEvent = new VisibilityEvent(Browser.this);					newEvent.display = getDisplay();					newEvent.widget = Browser.this;					if (visible) {						for (int i = 0; i < visibilityListeners.length; i++)							visibilityListeners[i].show(newEvent);					} else {						for (int i = 0; i < visibilityListeners.length; i++)							visibilityListeners[i].hide(newEvent);					}					break;				}				case ProgressChange : {					Variant arg1 = event.arguments[0];					int nProgress = arg1.getType() != OLE.VT_I4 ? 0 : arg1.getInt(); // may be -1					Variant arg2 = event.arguments[1];					int nProgressMax = arg2.getType() != OLE.VT_I4 ? 0 : arg2.getInt();					ProgressEvent newEvent = new ProgressEvent(Browser.this);					newEvent.display = getDisplay();					newEvent.widget = Browser.this;					newEvent.current = nProgress;					newEvent.total = nProgressMax;					if (nProgress != -1) {						for (int i = 0; i < progressListeners.length; i++)							progressListeners[i].changed(newEvent);					}					break;				}				case StatusTextChange : {					Variant arg1 = event.arguments[0];					if (arg1.getType() == OLE.VT_BSTR) {						String text = arg1.getString();						StatusTextEvent newEvent = new StatusTextEvent(Browser.this);						newEvent.display = getDisplay();						newEvent.widget = Browser.this;						newEvent.text = text;						for (int i = 0; i < statusTextListeners.length; i++)							statusTextListeners[i].changed(newEvent);					}					break;				}				case WindowClosing : {					CloseWindowEvent newEvent = new CloseWindowEvent(Browser.this);					newEvent.data = getDisplay();					newEvent.widget = Browser.this;					for (int i = 0; i < closeWindowListeners.length; i++)						closeWindowListeners[i].close(newEvent);					Variant cancel = event.arguments[1];					int pCancel = cancel.getByRef();					COM.MoveMemory(pCancel, new short[]{COM.VARIANT_FALSE}, 2);					dispose();					break;				}			}						/*			* Dispose all arguments passed in the OleEvent.  This must be			* done to properly release any IDispatch reference that was			* automatically addRef'ed when constructing the OleEvent.  			*/			Variant[] arguments = event.arguments;			for (int i = 0; i < arguments.length; i++) arguments[i].dispose();		}	};	site.addEventListener(BeforeNavigate2, listener);	site.addEventListener(CommandStateChange, listener);	site.addEventListener(DocumentComplete, listener);	site.addEventListener(NewWindow2, listener);	site.addEventListener(OnVisible, listener);	site.addEventListener(ProgressChange, listener);	site.addEventListener(StatusTextChange, listener);	site.addEventListener(WindowClosing, listener);		Variant variant = new Variant(true);	auto.setProperty(RegisterAsBrowser, variant);	variant.dispose();}