Memory leak (even after webclient.close())
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 25/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 停滯
- 技術堆疊
- java, javascript
- 領域
- backend
研究方向
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.
由索引模型根據 Issue 內容生成。
描述
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
- 主要語言
- JavaScript
- 星號
- 952
- 分支
- 183
- 平均合併
- 2 天 1 小時
- 30 天內合併 PR
- 1
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
HtmlUnit/htmlunit 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 68/100
-
難度 4/5 3-5 天 新手友好度 35/100
-
難度 4/5 3-5 天 新手友好度 45/100
-
難度 5/5 一週以上 新手友好度 25/100
-
難度 4/5 3-5 天 新手友好度 45/100
查看 HtmlUnit/htmlunit 的全部 Issue
相似的 Issue
-
enhancement
難度 2/5 1-3 小時 新手友好度 78/100
glossyio/traffic-monitor#264 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 72/100
-
難度 2/5 1-3 小時 新手友好度 88/100
micromatch/picomatch#243 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
getComputedStyle().display is "" for span, a, b, label and other inline elements instead of "inline"未關閉
難度 2/5 1-3 小時 新手友好度 76/100
capricorn86/happy-dom#2556 ·
維護者通常 1 天內回覆