Modify

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#21446 closed defect (fixed)

Memory leaks with TaggingPreset

Reported by: GerdP Owned by: team
Priority: normal Milestone: 21.12
Component: Core Version:
Keywords: Cc: skyper, stoecker

Description

This is a follow up of ticket:21360#comment:5.

Attachments (3)

21360.patch (1.7 KB ) - added by GerdP 3 years ago.
minimal patch to reduce memory leak
21360-work.patch (3.3 KB ) - added by GerdP 3 years ago.
also refresh presets in toolbar
21360-v3.patch (4.0 KB ) - added by GerdP 3 years ago.

Download all attachments as: .zip

Change History (23)

by GerdP, 3 years ago

Attachment: 21360.patch added

minimal patch to reduce memory leak

comment:1 by GerdP, 3 years ago

I don't yet understand why ToolbarPreferences keeps references to all actions (and thus also presets) that were ever loaded in field actions. This makes it impossible to free memory for presets.

by GerdP, 3 years ago

Attachment: 21360-work.patch added

also refresh presets in toolbar

comment:2 by GerdP, 3 years ago

Cc: skyper added

What should happen when a preset is removed for which an icon exists in the toolbar? The current code behaves a bit strange when this is done. Example steps to reproduce:

  1. Preset preferences -> Add preset Allergy
  2. Configure toolbar and add the preset Allergy|Baker icon
  3. Verify that the icon (and thus the preset) works as expected
  4. Preset preferences -> Remove the preset Allergy

Note that the baker icon still exists and the preset still works. Only after a restart the icon is removed. I would expect that the preset and the icon are removed immediately after step 4.

Last edited 3 years ago by GerdP (previous) (diff)

comment:3 by skyper, 3 years ago

How does this work with plugin actions?

First I thought sure, go ahead, but the more I think about the trickier it gets:

  1. Install some presets
  2. Nicely configure a customized toolbar
  3. Dislike the order of groups in preset menu
  4. Delete presets and add them in different order

As far as I know, icons are only reloaded on startup which does not help here, either.

comment:4 by marcello@…, 3 years ago

The toolbar should listen to TaggingPresetListener::taggingPresetsModified and update itself accordingly.

in reply to:  3 comment:5 by GerdP, 3 years ago

Replying to skyper:

How does this work with plugin actions?

Plugins are not unloaded. If you disable a plugin it is just not loaded on the next start.
The toolbar actions are stored in preference toolbar. This is just a collection of strings. If method ToolbarPreferences.refreshToolbarControl() is called, all "known" actions are parsed and the toolbar is refreshed. If an action is missing the list in toolbar is not changed, the icon is just not added to the toolbar.

in reply to:  4 comment:6 by GerdP, 3 years ago

Replying to marcello@…:

The toolbar should listen to TaggingPresetListener::taggingPresetsModified and update itself accordingly.

Yes. I've already added the listener in my patch. I just don't know for sure what changes this should trigger.

by GerdP, 3 years ago

Attachment: 21360-v3.patch added

comment:7 by GerdP, 3 years ago

Cc: stoecker added

I think this is ready to commit.

  • Memory leaks are fixed
  • Toolbar icon disappears when corresponding preset is removed
  • Toolbar icon reappears when corresponding preset is added

@Dirk: I still don't fully understand the purpose of the two maps actions and regactions in ToolbarPreferences. regactions was introduced for #2091. The committed code changes are more complex than the patches which were attached to the ticket and I have no idea yet if that was intended.

comment:8 by marcello@…, 3 years ago

Probably just clearing actions in ToolbarPreferences.loadActions would suffice. actions and regactions indeed look kind of redundant, and actions never gets properly cleared.

in reply to:  8 comment:9 by GerdP, 3 years ago

Replying to marcello@…:

Probably just clearing actions in ToolbarPreferences.loadActions would suffice. actions and regactions indeed look kind of redundant, and actions never gets properly cleared.

Do you mean instead of other code in my patch or in addition? Please attach a patch. My experience with dialogs is minimal.

comment:10 by marcello@…, 3 years ago

It looks like actions is initialized from the menu and it is needed only for the toolbar preferences dialog. I don't see any reason to keep it around after the preferences dialog is closed. So I propose a patch that makes actions local to the dialog.

in reply to:  10 comment:11 by stoecker, 3 years ago

Replying to marcello@…:

It looks like actions is initialized from the menu and it is needed only for the toolbar preferences dialog. I don't see any reason to keep it around after the preferences dialog is closed. So I propose a patch that makes actions local to the dialog.

I think that's right. In the beginning each action had to be registered. As that wasn't always done and probably never will be done somewhen a menu-scanning was added. These scanned entries very likely aren't relevant outside the dialog, but maybe they are required when loading/saving the config and handling the toolbar entries? Must be checked.

Actions can also be registered when not in the menu (and menu entries can be unregistered), so these two aren't identical, but they can have a lot of common entries.

comment:12 by marcello@…, 3 years ago

Having two things (actions, regactions) that do almost the same is probably a bad idea. In fact actions is hogging memory right now. Shouldn't the actions in the menu be registered when the presets menu is created and unregistered when it is destroyed?

Actually unregistering menu actions won't work because the two maps are merged in ToolbarPreferences.getDefinedActions() and that is also one reason the button still shows after the preset is unregistered from regactions. To get rid of a preset button you have to clean actions and regactions, as you are doing in the patch.

That leaves me unconvinced of the necessity of having actions at all, since we can reconstruct it from the menu any time we want.

comment:13 by GerdP, 3 years ago

OK if I commit my patch as is and you add further changes as a new patch?

comment:14 by marcello@…, 3 years ago

Please go ahead. If I find a better patch I will submit it later.

comment:15 by GerdP, 3 years ago

Resolution: fixed
Status: newclosed

In 18321/josm:

fix #21446: Memory leaks with TaggingPreset

  • don't always add ActiveLayerChangeListener in TaggingPreset constructor, only needed for some instances
  • let ToolbarPreferences implement TaggingPresetListener to update toolbar and free (most) refs to presets when a preset was uninstalled

comment:16 by Don-vip, 3 years ago

Milestone: 21.1121.12

Milestone renamed

comment:17 by gaben, 3 years ago

There is an issue with r18321, not all actions registering after the patch. I noticed this behaviour while tested my plugin. Compare the toolbar settings in r18319 and r18321. In the latter at least four core and possibly all plugin actions are missing.

Last edited 3 years ago by gaben (previous) (diff)

comment:18 by GerdP, 3 years ago

@gaben: Is this about EasyPresets? Please open a new ticket and give more details.

comment:19 by gaben, 3 years ago

Not related to EasyPresets. See new ticket #21730.

comment:20 by GerdP, 3 years ago

r18321 caused a regression, see #21740

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.