[BUG] Memory increases when same context is used
See original GitHub issueContext:
- Playwright Version: Latest (today is 26/044/2021)
- Operating System: Linux
- Node.js version: tested on both node.js version
- Browser: chromium
Describe the bug
I’m watching full-js apps (e.g react/angular websites). I initialize one instance, 1 browser and 1 page. I keep the page in cache & retrieving content every 2 seconds.
After 1/2hours, the memory goes crazy. I tried to reload() the page every 30 minutes. It doesn’t free the memory.
Only way to free the memory is closing the page and recreating a new one.
What could be the source of this memory leak? I suppose reload() frees the javascript-vm so it must be a leak internally to the page
Issue Analytics
- State:
- Created 2 years ago
- Reactions:61
- Comments:58 (10 by maintainers)
Top Results From Across the Web
EF Core Context is causing memory leak - Stack Overflow
I use the context within a service and just call this method: var chargePrice = await _teslaSolarChargerContext.ChargePrices .
Read more >Understanding Memory Leaks in Java - Baeldung
A Memory Leak is a situation where there are objects present in the heap that are no longer used, but the garbage collector...
Read more >WebView causes memory leak - Issue Tracker
I'm having the same issue with AdMob AdView objects. Prior to integrating with AdMob, I used the application context workaround, but AdViews don't...
Read more >Understanding memory leaks in Node.js apps - LogRocket Blog
The version of code that runs correctly one day might leak memory in the future due to a change in load, a new...
Read more >Find memory leaks with the CRT Library - Microsoft Learn
By default, _CrtDumpMemoryLeaks outputs the memory-leak report to the Debug pane of the Output window. If you use a library, the library ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think being able to have the page flush responses when new ones are received would be a useful feature, and along the lines of the way a typical browser handles responses. Maybe have it as a flag we can set?
While headless browsers have their origins in browser testing, and browser testing continues to be a major use case, data science is a rapidly growing field, and scraping is a major selling point for using headless browsers.
When scraping, you may not want to create an entirely new context with each data retrieval, as the cookies may be important for storing complex states or tokens. This leads to difficulties with the current Playwright implementation. Scrapers are primarily needed when lightweight APIs aren’t available or practical, and unfortunately in the modern web heavy pages of multiple megabytes of data can be included in each response.
If you’re getting HTTP responses every two seconds, you can easily amass over 1GB of additional memory leakage within an hour if all of those responses are being stored. In my case, after 43 minutes my playwright
nodeprocess crashed at 1.9GB of total memory size, with the errorFATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory. Increasing the memory limit will only delay the issue. Being able to prevent a context from cacheing all responses would be ideal.I have a case where I make several requests per minute, it leaks memory all over the place. I’ve tried closing pages, closing contexts, closing browsers, catching all the onClose events and reclosing everything all together, even closing the main playwright instance all the time, nothing works, it still leaks memory and at some point the GC thrashes completely with the CPU setting on fire.
Please provide and/or document a way to fully release all resources so that we can clear it out every now and then. Please don’t just focus on testing, it’s full of other use cases where playwright is needed to run long long times.