Re: [OpenMap Users] OMPoly memory leak

From: Rob Ratcliff <rratcliff_at_ticom-geo.com>
Date: Tue, 29 Apr 2008 08:39:25 -0600

There is a thread in the ProjectionSupport class that gets started when
you create an instance of OpenMap that you have to stop if you want OpenMap

Here are some sample diffs that I've sent into Don to add the capability
to shutdown the thread.

(I found this using the new NetBeans memory heap dump analyzer a few
months back. It works great for quickly finding memory leask if you
haven't tried it.)

===================================================================
RCS file: /cvs/openmap/openmap/src/openmap/com/bbn/openmap/MapBean.java,v
retrieving revision 1.21
diff -u -r1.21 MapBean.java
--- src/openmap/com/bbn/openmap/MapBean.java 29 Feb 2008 21:09:26
-0000 1.21
+++ src/openmap/com/bbn/openmap/MapBean.java 5 Mar 2008 13:17:50 -0000
_at_@ -1225,4 +1225,7 @@
         }
     }
 
+ public void shutdown() {
+ this.projectionSupport.terminate();
+ }
 }

===================================================================
RCS file:
/cvs/openmap/openmap/src/openmap/com/bbn/openmap/event/ProjectionSupport.java,v
retrieving revision 1.9
diff -u -r1.9 ProjectionSupport.java
--- src/openmap/com/bbn/openmap/event/ProjectionSupport.java 21 Jun
2007 21:42:01 -0000 1.9
+++ src/openmap/com/bbn/openmap/event/ProjectionSupport.java 21 Jan
2008 15:45:50 -0000
_at_@ -35,7 +35,7 @@
  */
 public class ProjectionSupport extends ListenerSupport {
 
- protected ProjectionChangeNotifier pcNotifier = new
ProjectionChangeNotifier();
+ protected ProjectionChangeNotifier pcNotifier = new
ProjectionChangeNotifier(this);
 
     /**
      * Construct a ProjectionSupport.
_at_@ -44,6 +44,11 @@
         this(null);
     }
 
+ public void terminate() {
+ this.pcNotifier.terminate();
+ this.pcNotifier = null;
+ }
+
     /**
      * Construct a ProjectionSupport.
      *
_at_@ -122,7 +127,7 @@
      * Swing thread do it. A new one is created for every projection
change, so
      * the current ProjectionEvent object is getting delivered with it.
      */
- protected class ProjectionChangeNotifier extends Thread {
+ protected static class ProjectionChangeNotifier extends Thread {
 
         private final Object lock = new Object();
 
_at_@ -135,7 +140,13 @@
         /* a flag to kneow if we are terminated (which is never ) */
         protected boolean terminated = false;
 
- public ProjectionChangeNotifier() {}
+ protected ProjectionSupport projectionSupport;
+
+ public ProjectionChangeNotifier(ProjectionSupport
projectionSupport) {
+ this.setDaemon(true);
+ this.setName("ProjectionChangeNotifierThread");
+ this.projectionSupport = projectionSupport;
+ }
 
         protected boolean isEventInProgress() {
             // synchronized(lock){
_at_@ -143,6 +154,13 @@
             // }
         }
 
+ public void terminate() {
+ this.terminated = true;
+ synchronized(lock) {
+ lock.notifyAll(); // wakes up thread if sleeping
+ }
+ }
+
         public void fireProjectionEvent(ProjectionEvent event) {
             synchronized (lock) {
                 nextEvent = event;
_at_@ -160,13 +178,13 @@
                     }
                 }
 
- if (projEvent != null && listeners != null) {
+ if (projEvent != null &&
this.projectionSupport.listeners != null) {
                     if (lstnrs == null) {
- lstnrs = (Vector) listeners.clone();
+ lstnrs = (Vector)
this.projectionSupport.listeners.clone();
                     } else {
                         lstnrs.clear();
                     }
- lstnrs.addAll(listeners);
+ lstnrs.addAll(this.projectionSupport.listeners);
                     for (Iterator it = lstnrs.iterator(); it.hasNext();) {
                         Object o = it.next();
                         if (nextEvent != null) {
_at_@ -191,6 +209,8 @@
                     }
                 }
             }
+ this.projectionSupport = null;
+ System.out.println("Projection Support Thread exiting");
         }
     }

jonathan.2.hart_at_bt.com wrote:
> Hi,
>
> I'm using OpenMap embedded in an Eclipse rich client application. I've
> got a memory leak, when the OpenMap window is closed the memory used by
> the map is not freed up. I've done some digging with profiling tools and
> it looks like the OMPoly objects used by OpenMap are not being garbage
> collected after the instance of OpenMap is being shutdown.
>
> Has anyone else had a similar problem, or any suggestions how to clear
> up these objects?
>
> Regards
>
> Jonathan
>
> --
> [To unsubscribe to this list send an email to "majdart_at_bbn.com"
> with the following text in the BODY of the message "unsubscribe openmap-users"]
>

--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Tue Apr 29 2008 - 09:41:15 EDT

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:09 EDT