This is the way how I get OSGi service:
ServiceReference reference = bundleContext.getServiceReference(Foo.class.getName());
Foo foo=(Foo) bundleContext.getService(reference);
What happens if I don't do bunldeContext.ungetSerivice(reference)
when I finished with service:
- If I registered service manually, for example in activator
- If I use declarative service and it is Singleton