swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

MessageProbe interferes with Java garbage collection in pretest 6 ?


From: Marshall, James A R
Subject: MessageProbe interferes with Java garbage collection in pretest 6 ?
Date: Tue, 17 Sep 2002 11:38:59 +0100

Hi,
  just to let you all know that I've encountered a problem while using
MessageProbes under Java in Swarm 2.2 pretest 6 (Windows 2000, JDK
1.3.1_02).
  The problem is that using a MessageProbe to call a method on an instance
of a class appears to leave Java's garbage collector unable to recycle that
instance even when all references to the instance have apparently been lost.
The problem is illustrated by the code below (it's short so I attached it).
If you compile and run the code as is you should find that the finalize
method of the class Test is called several times, as should be. However if
you remove the comment before the call to the MessageProbe function
doubleDynamicCallOn(...) the finalize method will never be called, implying
the garbage collector could not recycle the objects created.
  I'll investigate further by upgrading to a newer JDK, and looking at the
Swarm source if necessary, and report back. This does seem to be an
effective way to introduce a memory leak into your Java Swarm model though.
        James

class ITM
{
        public static void main(String args[])
        {
                class Test
                {
                        int mValue;

                        public int getValue()
                        {
                                return mValue;
                        }

                        public Test(int value)
                        {
                                mValue = value;
                        }

                        public void finalize()
                        {
                                System.out.println("finalised");
                        }
                }
                LinkedList list;
                Test test = null;
                MessageProbe probe = null;
                ProbeMap probeMap = null;
                int l1, l2, value;

                Globals.env.initSwarm("test", "0.0",
"address@hidden", args);
                list = new LinkedList();
                for (l1 = 0; l1 < 10; l1++)
                {
                        for (l2 = 0; l2 < 100; l2++)
                        {
                                test = new Test(1);
                                if (probeMap == null)
                                {
                                        probeMap =
Globals.env.probeLibrary.getCompleteProbeMapForObject(test);
                                        probe =
probeMap.getProbeForMessage("getValue");
                                }
//                              value = probe.longDynamicCallOn(test);
                                value = test.getValue();
                                list.addFirst(test);
                        }
                        list.clear();
                        Runtime.getRuntime().gc();
                }
        }
}

---
Dr James A R Marshall
Container World Project - http://www.ese.ic.ac.uk/research/containerworld/
Department of Earth Sciences and Engineering, Imperial College, London
Tel: +44 (0)20 7594 7493
Fax: +44 (0)20 7594 7444


                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]