MachinePublishers / jBrowserDriver

A programmable, embeddable web browser driver compatible with the Selenium WebDriver spec -- headless, WebKit-based, pure Java
Other
809 stars 143 forks source link

driver.reset() #204

Open Scisaga opened 7 years ago

Scisaga commented 7 years ago

when call driver.reset() in crawler threads, eg. change a upstreaming proxy, remote JBrowserDriverServer act unreasonable. both thread num and mem consume grow rapidly.

related code: Context.java Line 90 - 99

  void reset(JBrowserDriverServer driver) {
    removeItems();
    synchronized (lock) {
      setUpUserDataDir();
      ContextItem newContext = new ContextItem();
      newContext.init(driver, this);
      items.add(newContext);
      itemMap.put(newContext.itemId.get(), newContext);
    }
  }

since removeItems() just hide web elements using Toolkit util according to your code, may be the related threads and mem is not released. i don't quite understand this part of your code, may be you can give me some hints, thanks.

BTW. is there any change proxy method for driver?

hollingsworthd commented 7 years ago

Thanks for the info. You're right, Stage.close() doesn't actually free resources which is a bug in how it's used here.

The goal of the reset API is to re-initialize the state of the browser without actually re-initializing or classloading JavaFX or starting a new Java child process. Calling new JBrowserDriver() is expensive--although in context of loading a typical modern webpage (which is very expensive) it's not too bad.

Context is equivalent to the state of a browser. ContextItems are windows within that browser, that share the overall browser state, and each JBrowserDriver is a wholly separate browser instance running in a separate process.

Basically reset closes each browser window, gives you a new instance of WebView which is the JavaFX browser built on WebKit, clears cookies, user data, and other settings.

hollingsworthd commented 7 years ago

BTW. is there any change proxy method for driver?

Not aside from reset

andreaskas commented 7 years ago

Anu updates on this issue? Memory leaks using reset() are still here. Thanks

hollingsworthd commented 7 years ago

None yet

Gintasz commented 6 years ago

Any updates? I'm planning to try java 9, does it still leak on it?