Repository navigation
Issue #85: Free the native memory of WMI queries without waiting for the garbage collector - #86
Conversation
…the garbage collector Property values are read into a native VARIANT buffer freed right after the conversion, instead of a JNA VARIANT structure that allocates a native block for each pointer field of its union on every creation and read. Scalar values are converted straight from the buffer, exactly as before; arrays, objects and unexpected types still go through the JNA structure. IEnumWbemClassObject::Next reuses two native buffers for all the records. One Win32_Process query (534 rows) left 151,372 native blocks to the garbage collector, and now leaves 9. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Call VariantClear through a cached JNA Function instead of a library interface whose method name breaks the naming rule, and remove an unused import. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Test report: memory gain and non-regression (2026-11-18/19)Verdict: no regression found.
Host names are left out on purpose: the test machines are internal. 1. Root causeThe memory is not leaked: it piles up until the GC reclaims it.
These objects live long enough to be promoted to the old generation. G1 only reclaims them in a concurrent cycle, which happened about every two minutes on the test agent, so millions of native blocks wait between two cycles. With no On the agent that showed the problem (5 GB), Capping the heap on the customer's side would reduce the symptom without touching the cause. 2. Gain measured on the MetricsHub agentTwo MetricsHub Community agents ran side by side for 60 minutes with the same configuration: 3 WMI resources, collected every minute. The only difference was the WMI extension, built with wmi-java 1.0.07 or with this branch.
Private memory, sampled every 10 minutes:
jstat's 3. Unit tests
Each new test was run once with its own fix reverted, and failed. 4. WMI differential test on real machinesMethod
Results per machine
Notes on the columns:
Coverage
WinStorageSpaces, including the parameterized queries
What disturbed the remote runs On every server, the DCOM connection eventually fails with These 89 are on the 3 servers that stopped resolving in DNS during the retries (H, J, K). 73 of them are identical on other machines. The other 16 are 7 Director52ServeRAIDNT queries, such as 13 more machines could not be used: 7 refused access with the test accounts, 2 timed out on port 135 and 2 did not resolve in DNS. 5. MetricsHub CLI with this branchThe WMI extension of
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
bertysentry
left a comment
There was a problem hiding this comment.
This is a MASSIVE improvement of the library! ❤️
Fixes #85
What changes
WmiCimTypeHandler.getPropertyValueFromWbemObjectcallsIWbemClassObject::Get(vtable 4) with three native buffers: the VARIANT, the CIM type and the property name. All three are freed by try-with-resources, afterVariantClear.plFlavoris passed asNULL.convertScalarconverts the scalar values straight from the buffer:VT_EMPTY,VT_NULL,VT_BSTR,VT_BOOL,VT_UI1,VT_I2,VT_I4,VT_R4,VT_R8. It returns exactly whatconvert()returned through the JNA structure, including the same exceptions. Arrays, embedded objects and any other type returnNOT_SCALAR, so they still go through the JNAVARIANT, built on the same buffer.processWqlResultcallsIEnumWbemClassObject::Next(vtable 4) with two native buffers that are reused for every record and freed on return.VARIANTinstead of aVARIANT.ByReference.Results
Native blocks left to the garbage collector, for
SELECT Name, ProcessId, ThreadCount, HandleCount, CreationDate FROM Win32_Process(534 rows): 151,372 before, 9 after. The 9 remaining blocks are allocated once per query (the WQL string,GetNames).MetricsHub agent, side by side for 60 minutes. Both agents used the same configuration (3 WMI resources, 1-minute collect). The only difference was the WMI extension, built with wmi-java 1.0.07 or with this branch.
Memory$MemoryDisposer, live histogram)Non-regression
Unit tests:
testConvertScalarReturnsWhatConvertReturnsruns 22 VARIANT values (every handled VT, plus VT_I1, VT_UI2 and VT_I8, which must fall back) against 19 CIM types, including an array type and an unknown type.convertScalarmust return the same value and class as the old path, or the same exception, orNOT_SCALAR.testQueryLeavesNoNativeMemoryToTheGarbageCollectormeasures one query with no garbage collection running during it. It fails on 1.0.07 every time, with the default heap and with-Xmn8m.testUnknownEmbeddedObjectPropertyIsNull: an unknown sub-property of an embedded object still givesnull, and does not fail the query.Each new test was run with its own fix reverted, and failed.
Differential test on real Windows hosts:
__PATH,ASSOCIATORS OF, embedded objects). The$1queries are resolved like the connector does, for example the WinStorageSpacesMSFT_StorageReliabilityCounterones.root\hpq, Fujitsuroot\svsand ServeRAID.0x800706BFunder load and stay broken for both versions. That gave 1,363 RPC results in the first pass. Two retry rounds in fresh JVMs, and then the$1WinStorageSpaces queries run alone, brought this down to 89 untested results. All 89 are on 3 hosts that stopped resolving in DNS during the retries, and 73 of them are identical on other hosts.MetricsHub CLI (
-t win --wmi, automatic detection, 2 collects, 1.0.07 → this branch → 1.0.07):mvn verify(JDK 17): 83 tests, all pass.🤖 Generated with Claude Code