Hi all,
trying to trace a memory leak in geoserver today I made two
unpleasant discoveries.
The first one, most probably my fault, is that each DefaultMapLayer
attaches a listener to the FeatureSource it holds in order to notify
its parents about data changes (and thus instants were a proactive
map redraw may be intersting). Too bad it never removes those listeners.
The code looks like:
featureSource.addFeatureListener(sourceListener);
were source listener is an inner class. This is the part were I have to
apologize, and I'm going to fix this asap :-)
Well, you may say, this means that the FeatureSource will hold the inner
class, and thus the layer, for its entire life. Not to bad,
FeatureSource objects
are not usually long lived...
Heh, my friend, this is were you (and me) are wrong. Due to the scary
behaviour of FeatureListenerManager, a FeatureSource lives as long as its
datastore once a listener is attached to it. Don't believe me?
Look at the following code, and bear in my that we have on
FeatureListenerManager
per data store (it's in every datastore because it's handled in
AbstractDataStore):
public void addFeatureListener(FeatureSource featureSource,
FeatureListener featureListener) {
eventListenerList(featureSource).add(FeatureListener.class,
featureListener);
}
public void removeFeatureListener(FeatureSource featureSource,
FeatureListener featureListener) {
eventListenerList(featureSource).remove(FeatureListener.class,
featureListener);
}
public EventListenerList eventListenerList(FeatureSource
featureSource) {
synchronized (listenerMap) {
if (listenerMap.containsKey(featureSource)) {
return (EventListenerList) listenerMap.get(featureSource);
} else {
EventListenerList listenerList = new EventListenerList();
listenerMap.put(featureSource, listenerList);
return listenerList;
}
}
}
as you can see, once the featuresource enters the listenermap, there's
no way to
get it out. What's worse, FeatureSource has no method to "close" it, so
in fact there
would be no good place to perform house cleaning.
Now, I'd like suggestions... I see there's some code in the listener
that asks
for a centralized management, but if we don't have housekeeing too,
there's not
wonder things like geoserver will bomb after a while... (that's not to
say this
is the only leak around, btw).
Cheers
Andrea
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel