fix: cancel orphaned NewbieTask before overwrite to prevent memory leak#725
fix: cancel orphaned NewbieTask before overwrite to prevent memory leak#725xBuhari wants to merge 1 commit into
Conversation
Heap dump analysis showed 5,312 NewbieTask instances accumulating in the ScheduledThreadPoolExecutor queue, retaining ~4.85 GB of heap (26% of total). Root cause: setNewbie(true) created a new NewbieTask without cancelling the previous one, orphaning the old task in the executor queue with a strong CombatPlayer -> CraftPlayer reference chain. Fix: - Cancel existing newbieTask before overwriting in setNewbie() - Guard /newbie add to skip players already under newbie protection - Null out newbieTask reference after cancel in cleanForRemoval()
|
|
Overall Grade |
Security Reliability Complexity Hygiene |
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| Java | May 18, 2026 10:42a.m. | Review ↗ |
Important
AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.
PvPManager — Heap Dump AnalysisSource: Eclipse Memory Analyzer leak report ( This report covers only PvPManager ( SummaryPvPManager shows up as a major retainer in Leak Suspect 2 (orphaned Rough scale:
Using the suspect set average (~720 KB retained per This pattern matches newbie-protection timers not being cancelled when players disconnect, so tasks and Classes (PvPManager only)Only three PvPManager types appear in the exported dominator / reference data:
No other Retention path (main leak chain)MAT Reference Pattern for the Interpretation: Thousands of delayed tasks are still sitting in the executor queue. Each task keeps its Secondary references (same dump, smaller branches):
Instance counts (reference pattern)
Shallow heap on the path is small; almost all impact is retained ThreadsPvPManager threads in the dump (context class loader:
32 thread records match Combined retained heap on these thread objects is about 1.4 MB (thread locals + queue heads), excluding the bulk of player data held through queued tasks. Context in Leak Suspect 2MAT flags 6,731
PvPManager is not the only possible referrer (other threads also point at Likely cause
Newbie protection duration, re-log behaviour, and async quit handling should be checked against PvPManager config and version release notes. Recommendations
Raw identifiers (for MAT follow-up)
|
|
This seems like it would only happen when running |
🐛 Memory Leak Fix: Orphaned NewbieTask accumulation
Root Cause
Heap dump analysis (Eclipse MAT) revealed 5,312 NewbieTask instances accumulating
in the
ScheduledThreadPoolExecutorqueue, retaining ~4.85 GB of heap (26% of total).setNewbie(true)was creating a newNewbieTaskwithout cancelling the previous one.The orphaned task remained in the executor queue (potentially for hours) while holding
a strong reference chain:
Easy trigger: running
/newbie addon a player already under newbie protection,since there was no
isNewbie()guard before callingsetNewbie(true).Fix
CombatPlayer.setNewbie()— Cancel existingnewbieTaskbefore overwriting the referenceNewbie.java(AddNewbieCommand) — Guard withisNewbie()check to prevent repeated schedulingCombatPlayer.cleanForRemoval()— Null outnewbieTaskafter cancel to release the reference immediatelyDescription
Memory leak fix for orphaned
NewbieTaskinstances causing excessive heap retention.No behavioral changes to newbie protection logic.