if (serviceEvent != null) { framework.serviceEvent.removeListener(this); serviceEvent = null;
synchronized (framework.serviceEvent) { if (serviceEvent != null) { framework.serviceEvent.removeListener(this); serviceEvent = null; }
	protected void close() {		valid = false; /* invalidate context */		if (serviceEvent != null) {			framework.serviceEvent.removeListener(this);			serviceEvent = null;		}		if (frameworkEvent != null) {			framework.frameworkEvent.removeListener(this);			frameworkEvent = null;		}		if (bundleEvent != null) {			framework.bundleEvent.removeListener(this);			bundleEvent = null;		}		if (bundleEventSync != null) {			framework.bundleEventSync.removeListener(this);			bundleEventSync = null;		}		/* service's registered by the bundle, if any, are unregistered. */		ServiceReference[] publishedReferences = null;		synchronized (framework.serviceRegistry) {			publishedReferences = framework.serviceRegistry.lookupServiceReferences(this);		}		if (publishedReferences != null) {			for (int i = 0; i < publishedReferences.length; i++) {				try {					((ServiceReferenceImpl) publishedReferences[i]).registration.unregister();				} catch (IllegalStateException e) {					/* already unregistered */				}			}		}		/* service's used by the bundle, if any, are released. */		if (servicesInUse != null) {			int usedSize;			ServiceReference[] usedRefs = null;			synchronized (servicesInUse) {				usedSize = servicesInUse.size();				if (usedSize > 0) {					if (Debug.DEBUG && Debug.DEBUG_SERVICES) {						Debug.println("Releasing services"); //$NON-NLS-1$					}					usedRefs = new ServiceReference[usedSize];					Enumeration refsEnum = servicesInUse.keys();					for (int i = 0; i < usedSize; i++) {						usedRefs[i] = (ServiceReference) refsEnum.nextElement();					}				}			}			for (int i = 0; i < usedSize; i++) {				((ServiceReferenceImpl) usedRefs[i]).registration.releaseService(this);			}			servicesInUse = null;		}		bundle = null;	}