You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Amichai Rothman (JIRA)" <ji...@apache.org> on 2013/04/14 12:16:16 UTC

[jira] [Created] (DOSGI-171) service objects are never released (using ungetService)

Amichai Rothman created DOSGI-171:
-------------------------------------

             Summary: service objects are never released (using ungetService)
                 Key: DOSGI-171
                 URL: https://issues.apache.org/jira/browse/DOSGI-171
             Project: CXF Distributed OSGi
          Issue Type: Bug
    Affects Versions: 1.4.0, 1.5
            Reporter: Amichai Rothman


The BundleContext.getService() spec/API states that for every time this method returns a service object, it must later be released using BundleContext.ungetService(). Further, after ungetService is called, all references to the service object should be removed (set to null) so that it can be properly released.

Currently, there are many usages of getService in the code, but none of them release the reference as required.

The recommendation seems to be to use service trackers where possible instead of directly accessing the getService/ungetService APIs, since the ServiceTracker was created for this exact purpose - to properly handle all the bookkeeping for service references. Alternatively, in places in which a ServiceTracker is not appropriate and the services are used locally, the getService call should be followed by a try-finally block which always ungets the service when done as is standard practice with resource management. Finally, in places in which the service access is not contained in a local method, and is stored in a field or passed around, proper resource release should be performed (ungetService called and references nulled afterwards) in an appropriate way for those cases (when closing or releasing the containing class instance, etc.)


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira