Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avoid mem leak for improper use of registerObject (#451)
Calling `Monitors.registerObject` with a monitor such as a `BasicCounter` instance will register an empty composite monitor with an id like `default:class=BasicCounter`. When using the spectator integration this would result is a memory leak because it needs to track the instances to be able to aggregate the results. This change updates the registration to remove any previous copies and overwrite which is the default for servo. It also double checks if it is an empty basic composite and just ignores those since they will never have any monitors to collect. It is a bit difficult to test without a bunch of reflection to dig into the guts of the meter state. I did reproduce in a debugger using the following test case and confirm the state is no longer growing: ```java @test public void testBasicCounterLoop() { for (int i = 0; i < 1000; ++i) { BasicCounter c = new BasicCounter(CONFIG); Monitors.registerObject(c); c.increment(); } assertEquals(1000, registry.counter(ID).count()); } ```
- Loading branch information