Pierre De Rop created FELIX-6886:
------------------------------------
Summary: Instance-bound dependencies leak in ComponentImpl events
map
Key: FELIX-6886
URL: https://issues.apache.org/jira/browse/FELIX-6886
Project: Felix
Issue Type: Bug
Components: Dependency Manager
Reporter: Pierre De Rop
Assignee: Pierre De Rop
When a component adds a dependency from its init() method (an "instance-bound"
dependency, which is also what the annotation runtime does), the dependency is
removed from the component's dependency list when the instance is destroyed.
However, its entry is never removed from the internal m_dependencyEvents map of
ComponentImpl.
Each destroy/init cycle therefore leaves behind a DependencyContext (with its
tracker, its callbacks and a reference to the component) and its set of events.
The map grows for as long as the component lives.
Example:
public class Activator extends DependencyActivatorBase {
@Override
public void init(BundleContext ctx, DependencyManager dm) {
dm.add(createComponent()
.setImplementation(MyComponent.class)
.add(createServiceDependency()
.setService(Required.class)
.setRequired(true)));
}
}
public class MyComponent {
volatile DependencyManager m_dm;
volatile Component m_component;
void init() {
// dependency declared by the instance itself: instance-bound
m_component.add(m_dm.createServiceDependency()
.setService(Other.class)
.setRequired(false));
}
}
1. Required is registered: MyComponent is instantiated and init() adds the
Other dependency.
2. Required is unregistered: the instance is destroyed, and the Other
dependency is removed from the component and stopped.
3. Required is registered again: a new instance is created and init() adds a
new Other dependency.
4. Repeat steps 2 and 3 1000 times.
Observed: after 1000 cycles, m_dependencies contains 1 entry, but
m_dependencyEvents contains 1001 entries.
Expected: once an instance-bound dependency has been removed from the
component, no reference to it (or to its events) is retained.
m_dependencyEvents should only contain entries for the dependencies currently
registered in the component, as is the case when a dependency is removed
through Component.remove(Dependency).
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)