﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
19793	RFC: Memory leaks: Bad programming pattern reg. listeners	GerdP	team	"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.
{{{
#!java
  MainApplication.getLayerManager().addLayerChangeListener(new GpxLayerAddedListener());
}}}
or the pattern `[Mm]ain.*Listener\(.* \-\>`
{{{
#!java
  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.
"	task	new	normal		Core				
