Modify

Opened 4 years ago

Last modified 4 years ago

#19793 new task

RFC: Memory leaks: Bad programming pattern reg. listeners

Reported by: GerdP Owned by: team
Priority: normal Milestone:
Component: Core Version:
Keywords: Cc:

Description (last modified by GerdP)

I've noticed that a lot of memory leaks occur where source code contains either this regex pattern
[Mm]ain.*Listener\(new
This matches eg.

  MainApplication.getLayerManager().addLayerChangeListener(new GpxLayerAddedListener());

or the pattern [Mm]ain.*Listener\(.* \-\>

  Preferences.main().addPreferenceChangeListener(e -> updateSystemProperties());

Reason is quite obvious:
The code fragments create a new Listener and add it to a global list, but the ref to the new listener instance is not stored and therefore removeListener() is never called. If the code is only executed once in a JOSM session this is no big problem but it's hard to find out, so I think we should avoid this. Even the patterns Listener\(new and Listener\(.* \-\> are at least error prone.

Attachments (0)

Change History (2)

comment:1 by GerdP, 4 years ago

Description: modified (diff)

comment:2 by GerdP, 4 years ago

In 17055/josm:

see #19793: Memory leaks: Bad programming pattern reg. listeners
SearchDialog did not remove TaggingPresetListener

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain team.
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from team to the specified user.
Next status will be 'needinfo'. The owner will be changed from team to GerdP.
as duplicate The resolution will be set to duplicate. Next status will be 'closed'. The specified ticket will be cross-referenced with this ticket.
The owner will be changed from team to anonymous. Next status will be 'assigned'.

Add Comment


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