[ https://issues.apache.org/jira/browse/SOLR-13677?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16900959#comment-16900959 ]
Christine Poerschke commented on SOLR-13677: -------------------------------------------- {code:java} - public void registerGauge(SolrInfoBean info, String registry, Gauge<?> gauge, String tag, boolean force, String metricName, String... metricPath) { + public GaugeRef registerGauge(SolrInfoBean info, String registry, Gauge<?> gauge, String tag, boolean force, String metricName, String... metricPath) { {code} The above {{registerGauge}} method change to makeĀ it return a gauge reference encourages but does not ensure that the caller 'remembers' the reference and so that it is later then included in the unregister calls. There's also a small amount of repetition w.r.t. iterating over the {{myGauges}} collection and unregistering the elements. I wonder if some sort of container or wrapper class might be helpful i.e. {{SolrMetricManager.registerGauge}} would be sure to call 'remember' for the gauge and the close(\?) method of the producer would call the 'forgetAll' method. What do you think? {code:java} + class FooBar { + private final List<GaugeRef> gaugeRefs = new ArrayList<>(); + void remember(GaugeRef gaugeRef) { + gaugeRefs.add(gaugeRef); + } + void forgetAll() { + for (GaugeRef gaugeRef : gaugeRefs) { + gaugeRef.unregister(); + } + gaugeRefs.clear(); + } + } + + public void registerGauge(FooBar memory, SolrInfoBean info, String registry, Gauge<?> gauge, String tag, boolean force, String metricName, String... metricPath) { + memory.remember(registerGauge(info, registry, gauge, tag, force, metricName, metricPath)); + } + + private GaugeRef registerGauge(SolrInfoBean info, String registry, Gauge<?> gauge, String tag, boolean force, String metricName, String... metricPath) { - public void registerGauge(SolrInfoBean info, String registry, Gauge<?> gauge, String tag, boolean force, String metricName, String... metricPath) { ... {code} > All Metrics Gauges should be unregistered by the objects that registered them > ----------------------------------------------------------------------------- > > Key: SOLR-13677 > URL: https://issues.apache.org/jira/browse/SOLR-13677 > Project: Solr > Issue Type: Improvement > Security Level: Public(Default Security Level. Issues are Public) > Components: metrics > Reporter: Noble Paul > Priority: Major > Time Spent: 10m > Remaining Estimate: 0h > > The life cycle of Metrics producers are managed by the core (mostly). So, if > the lifecycle of the object is different from that of the core itself, these > objects will never be unregistered from the metrics registry. This will lead > to memory leaks -- This message was sent by Atlassian JIRA (v7.6.14#76016) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org