Project

General

Profile

Bug #11738

Fix FWD client memory leaks

Added by Teodor Gorghe 3 months ago. Updated 11 days ago.

Status:
WIP
Priority:
Normal
Assignee:
Target version:
-
Start date:
Due date:
% Done:

90%

billable:
No
vendor_id:
GCD
case_num:
version_reported:
version_resolved:
production:
No
env_name:
topics:

History

#1 Updated by Teodor Gorghe 3 months ago

While #11326 and #11327 has decreased the minimal client memory requirement and memory spikes, there are some scenarios which causes memory leaks.
Constantin has made a memory leak fix in #11580 regarding a scenario which uses persistent triggers, but there are still some memory leaks for the FWD client.

When running the FWD client with 64M heap, for a large GUI app, with intensive work, that session survives just a short time.

#4 Updated by Constantin Asofiei 3 months ago

What exactly is leaking?

#5 Updated by Teodor Gorghe 3 months ago

I don't know exactly what is leaking, but I have saw a substantial memory difference (+20M) cold vs hot (on the same initial screen).
Capturing the heap dumps right now.

#6 Updated by Teodor Gorghe 3 months ago

Attached on devsrv01:/tmp/tg.20260813/ (cold.hprof and hot.hprof).

Analyzing right now.

#7 Updated by Constantin Asofiei 3 months ago

Teodor Gorghe wrote:

Attached on devsrv01:/tmp/tg.20260813/ (cold.hprof and hot.hprof).

Analyzing right now.

There is no cold.hprof.

#8 Updated by Teodor Gorghe 3 months ago

Done.

#9 Updated by Teodor Gorghe 3 months ago

This is what AI has found during heap dump analysis. I will do the same smoke test and also record the heap dump on the server-side.

Heap leak analysis - cold vs hot

Both dumps: same screen, idle, after GC, 10 minutes apart. Live heap grew 43.1 MB -> 51.9 MB (+8.8 MB, ~53 MB/hour). About 6.0 MB sits in the maps below.

Leaks found

No Container Grew What it pins
1 FontManager$WorkArea.orphanFontResolvers 32 -> 1458 1387 dead radio buttons, 2.92 MB
2 AbstractGuiDriver.pendingTtWorkers 86 -> 455 138 browse columns, 66 dead menus
3 WidgetRegistry.widgetList 423 -> 806 widgets never unregistered
4 ClientConfigManager.widgetCfg / activeConfigs / backupConfigs 391 -> 770 each button, browse and frame configs
5 AbstractGuiDriver.widgetsRegions 164 -> 1540 rects bounds cache, 29 window ids from 3
6 MouseHandler$WorkArea.actions / cachedActions 105 -> 157, 155 -> 194 mouse action lists
7 GuiWebDriver.imageUsages / imageSeals 42 -> 375 each image bitmaps

Root cause

All seven are widget-keyed side tables. Each is cleaned only on widget teardown, and teardown never runs.

  • RadioSet.refreshItems() calls buttons.clear() and rebuilds every button. The old buttons are never destroyed. There is no destroy call anywhere in RadioSet.java, RadioSetGuiImpl.java or RadioButtonGuiImpl.java.
  • Browse columns and menus are dropped the same way.
  • Because destroy() never runs, notifyWidgetDestroyed(), WidgetRegistry.remove() and the MouseHandler cleanup never run either.
  • The strong map keys then pin each dead widget plus its resolvers, configs, insets, points and labels.

Not leaks

  • AbstractGuiDriver.textMetricsCache - 341 -> 1995, but it is an LFUAgingCache that evicts when full. Cache warm-up, ~0.55 MB.
  • MethodHandle, MemberName, MethodType, Method, Constructor growth - JVM lambda and reflection warm-up, ~0.35 MB.

Still open

About 1.9 MB of widget-tree growth: FrameGuiImpl 33 -> 55, ScrollPaneGuiImpl 33 -> 58, BorderedPanelGuiImpl 72 -> 143, ScrollBarGuiImpl 59 -> 121, ButtonConfig 282 -> 582. Dead subtrees still hanging off live parents. Same root cause, but no single retaining edge isolated yet.

#10 Updated by Teodor Gorghe 3 months ago

Made some improvements regarding fixing some FWD client memory leaks.

Initially, the heap was increasing with 12M on that 5 minute smote test.
I have fixed the radio button memory leak and the one related with the widgetList, and the leak has reduced to 6M.

#11 Updated by Teodor Gorghe 3 months ago

Created task branch 11738a and committed revision 16725:
  • Added initial work: Fixed widget and radio set memory leaks.

#12 Updated by Teodor Gorghe 17 days ago

I have reproduced the Frame.savedTabOrder memory leak, and it is simple to reproduce:

#13 Updated by Teodor Gorghe 17 days ago

Fix for the savedTabOrder memory leak is in 11738/r16727.

I have replaced the array with a set because of the removal that needs to be O(1). With an array, that wasn't possible.

#14 Updated by Teodor Gorghe 14 days ago

  • Status changed from New to WIP
  • Assignee set to Teodor Gorghe
  • % Done changed from 0 to 100
  • reviewer Stanislav Lomany added

Stanislav, please review the changes. Most of the changes are browse related.

#15 Updated by Teodor Gorghe 14 days ago

  • Status changed from WIP to Review

+ Stanislav.

#16 Updated by Stanislav Lomany 14 days ago

  • Status changed from Review to WIP
  • % Done changed from 100 to 90

11738a rev 16727

  • I reviewed the browse part, it looks good.
  • Regarding the changes in Frame:
    Set<Widget<O>> savedTabOrder
    

    Doesn't the name suggest that the data structure should be ordered? It is initialized as LinkedHashSet, so the order should be preserved, but we cannot declare it like this. Also, is there a reason why a set is used? Is it possible that there are duplicate items in a tab order? Can't we use a List?
  • Please change the reviewer to review non-Browse* files. AI gave me these GuiOutputManager concerns, not sure how legit they are.

[MAJOR] functional GuiOutputManager.releaseWidgetResources: Now calls the new deregisterWidget(int, Widget) overload, which SwingGuiDriver does not override. Its deregisterWidget(int) override is the only caller of SwingMouseHandler.deregisterWidgetActions, so under the Swing GUI driver no widget released through AbstractWidget.destroy has its Swing mouse actions removed any more. Trigger: DELETE WIDGET of a CREATE WINDOW window. WindowGuiImpl.init registers a MouseMoveable for the title bar via registerMoveableWidget; the title bar sits inside contentPane, and WindowGuiImpl.destroy only deregisters its direct children and the workspace, so the title bar's only cleanup was WindowTitleBar.destroy -> releaseWidgetResources -> SwingGuiDriver.deregisterWidget(int), which now stops at AbstractGuiDriver.deregisterWidget(int, Widget). The MouseMoveable stays in the session-scoped SwingMouseHandler actions map, holds the WindowTitleBar (final MouseWidgetAction.widget), whose wndParent retains the whole destroyed WindowGuiImpl: a new per-window leak in the Swing client, introduced by a leak-fix change. (ModalWindow dialogs are still cleaned in hide() via the 1-arg call; the BrowseGuiImpl.cleanupEditor path is bypassed too but editors register no Swing actions.) Fix: move the SwingGuiDriver override onto deregisterWidget(int, Widget), as was done for GuiWebDriver; the 1-arg override can then be dropped, since AbstractGuiDriver.deregisterWidget(int) delegates to the 2-arg one.

#17 Updated by Dean Macken 12 days ago

is there a likely timeline for this?

#18 Updated by Teodor Gorghe 12 days ago

  • reviewer Hynek Cihlar added

The issue is easy to fix, I'll fix that and I will ask for Hynek to look into these changes.
Most likely it will be merged into trunk next week.

#19 Updated by Razvan-Nicolae Chichirau 11 days ago

Teodor Gorghe wrote:

  • Browse columns and menus are dropped the same way.

Please note that starting with trunk rev. 16817 the browse columns and their references should be deleted in the proper way.

#20 Updated by Teodor Gorghe 11 days ago

Ok, then I should rebase the branch and check if that still holds.

Also available in: Atom PDF