Memory leak (even after webclient.close())
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 25/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- java, javascript
- Bereich
- backend
Rechercherichtung
Start by comparing this report with linked issue #639 and the memory guidance in the HtmlUnit FAQ; the example creates and closes a WebClient after loading a page and waiting for background JavaScript. Investigate what remains reachable after close and whether the reported heap growth is retained library state or expected JVM behavior. Done means identifying and addressing the cause, with a regression test that demonstrates cleanup across repeated client use.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Hello,
I want to thank you for your amazing work. I'm using your lib since almost 1 year now and it's really nice.
I'm having an issue about memory (heap memory).
Showcase 1: I'm starting my app without doing any scrap
Heap: 74Mo
Showcase 2: I'm starting my app and doing 1 scrap with close
Heap: 256Mo
class ArkeaArenaFetcher {
fun fetch(): List<EventJpa> {
val webClient = WebClient().apply {
options.isCssEnabled = true
options.isJavaScriptEnabled = true
cssErrorHandler = SilentCssErrorHandler()
javaScriptErrorListener = SilentJavaScriptErrorListener()
options.isThrowExceptionOnFailingStatusCode = false
}
return try {
val page = webClient.getPage<HtmlPage>("https://www.arkeaarena.com/fr/programmation/tous-les-evenements/#")
webClient.waitForBackgroundJavaScript(4000)
val container: HtmlElement = page.getFirstByXPath("//div[@class='events-list ajaxed']/div[@class='container']")
val rawEvents = container.getByXPath<HtmlElement>("a")
rawEvents.map(::htmlToInfra)
} catch (e: Exception) {
emptyList()
} finally {
webClient.close()
}
}
private fun htmlToInfra(html: HtmlElement): EventJpa {
// convert html to Kotlin object
...
}
}
Showcase 3: I'm starting my app and doing 1 scrap with close + other clean + gc
Heap: 166Mo
The code is the same as the showcase 2 but only the finally clause is changing like below
finally {
webClient.cache.clear()
webClient.topLevelWindows.forEach { it.close(false) }
webClient.topLevelWindows.forEach { it.jobManager.removeAllJobs() }
webClient.cookieManager.clearCookies()
webClient.close()
System.gc()
}
The issue here is even when I'm closing the webclient instance there is still memory which is not released. Here in my example code I'm dealing with a single source but in production I'm dealing with multiple sources.
I also tried
.usein Kotlin (try with resources) (article)
Other info
- Language: Kotlin
- HtmlUnit version:
3.9.0(the behaviour is the same on older versions)
Article read about the memory subject:
- https://maxrohde.com/2013/01/05/fix-htmlunit-memory-leak
- https://htmlunit.sourceforge.io/faq.html#MemoryLeak
Similar issues
- #639
- Vorherrschende Sprache
- JavaScript
- Sterne
- 952
- Forks
- 183
- Ø Merge
- 2 T. 1 Std.
- Gemergte PRs (30 T.)
- 1
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus HtmlUnit/htmlunit
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 45/100
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 45/100
Alle Issues in HtmlUnit/htmlunit
Ähnliche Issues
-
[CLI] Clarify distinction between 'capture camera' and 'capture screen' in help text and outputOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
espressif/esp-vision#18 ·
-
verified
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100
Maintainer antworten meist innerhalb von 5 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 66/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
Maintainer antworten meist innerhalb von 1 Tag