Skip to content

Add private_usage target to find_memleak - Enrich leak detection with a new measurement method. - #996

Merged
junkmd merged 6 commits into
enthought:mainfrom
junkmd:memleak_private_usage
Nov 17, 2026
Merged

junkmd merged 6 commits into
enthought:mainfrom
junkmd:memleak_private_usage

Conversation

@junkmd

@junkmd junkmd commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Related to #971

Summary

Add a new target argument to find_memleak. It can now choose between "working_set" (the old way) and "private_usage" (a new way).
The new way uses PrivateUsage from PROCESS_MEMORY_COUNTERS_EX / PROCESS_MEMORY_COUNTERS_EX2, which is the Commit Charge. This gives the test a second, better way to find memory leaks.

Why

Until now, find_memleak had only one way to measure memory: the Working Set Size. This is the amount of memory that is now in the physical RAM. It is easy to change by other things, so a leak can be hidden.
A real leak is memory that was committed but never freed. The Working Set Size does not show this well.

By adding private_usage, the test can now measure all committed private memory, even if the pages are not in RAM right now. This is a stronger way to find leaks.
It is not a replacement. It is an addition. Now the test has two methods, and the user can pick the better one.

Trade-offs: one more method, not a simpler one

Pros: Two ways to measure, so the test is harder to fool. The new way catches leaks that the old way can miss. The test suite is richer.

Cons: The new way needs new structures (PROCESS_MEMORY_COUNTERS_EX and PROCESS_MEMORY_COUNTERS_EX2). It needs more code. On old Windows, it falls back to the basic structure.

Justification

The change does not change the old behavior. It only adds a new choice. The old tests still pass.
The new tests check that the new way works and that a wrong target gives an error.
This is a small, safe step that makes the test method stronger.

Out of Scope

  • Making private_usage the default target.
  • Changing the old working_set behavior.

@junkmd junkmd added this to the 1.5.1 milestone Nov 17, 2026
@junkmd junkmd added enhancement New feature or request tests enhance or fix tests labels Nov 17, 2026
@codecov-commenter

codecov-commenter commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.92857% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.71%. Comparing base (17242b9) to head (002e419).

Files with missing lines Patch % Lines
comtypes/test/find_memleak.py 79.54% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #996      +/-   ##
==========================================
- Coverage   91.74%   91.71%   -0.04%     
==========================================
  Files         150      150              
  Lines       15380    15424      +44     
==========================================
+ Hits        14111    14146      +35     
- Misses       1269     1278       +9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@junkmd
junkmd merged commit dbdbe10 into enthought:main Nov 17, 2026
68 checks passed
@junkmd
junkmd deleted the memleak_private_usage branch November 17, 2026 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request tests enhance or fix tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants