Erwin Bronkhorst created FELIX-5861:
---------------------------------------
Summary: ComponentInstances are disposed before disposal of
ComponentFactory
Key: FELIX-5861
URL: https://issues.apache.org/jira/browse/FELIX-5861
Project: Felix
Issue Type: Bug
Components: Declarative Services (SCR)
Reporter: Erwin Bronkhorst
When a bundle that contains a {{ComponentFactory}} is stopped, all
{{ComponentInstances}} in the bundle are disposed first, and after that the
{{ComponentFactory}} itself [1]. I think it is better if this would be the
other way around.
Given a situation in which component X has a static mandatory binding to the
{{ComponentFactory}} Y and created {{ComponentInstance}} Z using
{{y.newInstance()}}. If the bundle containing Y is stopped, the following order
of events happens:
# All {{ComponentInstances}} created by Y are disposed.
# Y is going to be disposed, and for that the SCR deactivates component X.
# The unbind-methods in X are called.
# The {{ComponentFactory}} Y is deactivated and disposed.
As far as I know, component X get no trigger of event 1. This means that the
{{ComponentInstance}} Z can be disposed without component X knowing this. I
have seen a situation in which component X tries to use {{ComponentInstance}} Z
after event 1, but before event 2 resulting in a runtime exception.
I think that, because component X created the {{ComponentInstance}} Z,
component X is responsible of disposing the instance. It should dispose the
created {{ComponentInstances}} when X is deactivated. Of course, to prevent
garbage in the registry, it is wise to dispose all remaining
{{ComponentInstances}} when the bundle is stopped, in case some components
failed to cleanup correctly.
So in short: who is the owner of a {{ComponentInstances}}, created by
{{ComponentFactory.newInstance()}} and who is responsible for cleaning it up?
- If it is the component that called {{newInstance()}}, I think the dispose of
the factory should be done before the dispose on the (remaining)
{{ComponentInstances}}. This way, the unbind of the factory is called before
the {{ComponentInstance}} is disposed.
- If it is the {{ComponentFactory}} that created the instance, is there a
possibility to get a notification when the {{ComponentInstance}} is disposed,
so the application can respond to it?
[1]
[https://github.com/apache/felix/blob/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java#L350]
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)