BrowserContext resource reclamation in high-volume test cycles
19K reputation · 21 Sept 2020, 16:36 UTC
BrowserContext Memory Management
Playwright provides BrowserContext to isolate test environments without the overhead of restarting the entire browser process. In large-scale test suites where hundreds of contexts are created and destroyed sequentially, the goal is to ensure the browser process memory footprint remains stable.
While browserContext.close() is used to release session resources, there is uncertainty regarding the efficiency of memory reclamation for the underlying browser process after repeated cycles of context creation and destruction.
If pages are explicitly closed before the context is terminated, it is unclear if the browser process returns to its baseline resident set size (RSS) or if a gradual increase in heap usage persists over time.
- Does the browser process fully reclaim memory allocated to a
BrowserContextonceclose()is called? - Is there a documented threshold for the number of context cycles before a browser restart is required to prevent memory exhaustion?