tjxy573
tjxy573

Reputation: 51

Why does Selenium uses a lot of memory

I want to know selenium with firefox question, I used Firefox version 56.0.2,selenium3.5.1,and geckodriver 0.19.1,server ubuntu(x64) os,firefox --headless mode I find when I run my app for a long time, the firefox memory will increase a lot, such 400MB or more, and when I let firefox open about:blank, the memory don not decrease I want to know how to decrease the firefox memory (do not kill the firefox process), only use the selenium to control firefox or start firefox with some config I want to open "about:blank" or other URL to reduce memory,but I find it doesn't work;

Upvotes: 2

Views: 7873

Answers (2)

Rafa
Rafa

Reputation: 1495

One workaround:

  • check the memory usage,
  • if it reaches a limit,
  • reset the driver (quit, wait some seconds, init again), and
  • continue the test.

Resetting the driver will free up resources; that's one way you can have control over the memory consumption.

Upvotes: 1

undetected Selenium
undetected Selenium

Reputation: 193268

No,Selenium itself doesn't uses any memory. It's the WebDriver and Web Browser processes which consumes the memory. For an example when you create a new instance of any WebDriver variant to start a relevant Web Browsing Session, both the process consumes memory.

Now the different Browser Client variants will follow different and distinct methods and style to initiate, manage and teardown the browser internal process. So memory consumption will be different for the different browsers.

Answering your questions :

  • When I run my app for a long time, the firefox memory will increase a lot : In-coarse of handling a active browsing session, the browser binary have to keep track a lot of memory (stack memory / heap memory) resources time to time. Hence memory consumption can go up/down depending on situation.

  • I want to know how to decrease the firefox memory : No, you have no control over the memory consumption of a browser.

Solution

Web Browsers have evolved a lot recently. Each of the Web Browser variants e.g. Mozilla, Chrome and Internet Explorer are continuously working on a more momery efficient browser process. You can take the following steps for your Automated Tests to consume the optimum memory :

  • Keep the JDK Version updated to the latest versions as each release aims towards optimum memory utilization.
  • Keep the Selenium Version updated to the latest versions as each release aims towards better memory management.
  • Keep the WebDriver Version updated to the latest versions as each release aims towards better memory management.
  • Keep the Web Browser Version updated to the latest versions as each release aims towards better memory utilization.
  • If the base version of your Web Browser is too older, you may consider to uninstall the Web Browser through Revo Uninstaller and install a recent stable and GA version of the Web Browser .

  • Use CCleaner tool before and after your Test Execution to wipe off the OS system chores.

  • Perform the Test Execution in an isolated system free from Manual Intervention

  • Keep the Test System within the Test Lab well equipped with the Hardware Requirements to execute the Test Suites.

Upvotes: 4

Related Questions