0 Replies Latest reply on Dec 30, 2002 6:02 PM by Ben Cox

    Primary Key objects not being garbage collected

    Ben Cox Newbie

      Hello,
      I have been struggling with a memory leak in my application for some time. After eliminating a few other offenders (using OptimizeIt), I've discovered that my multi-part primary key classes aren't always being cleaned up. These beans are dependents of another bean, and it appears that this only happens when they are created in the process of getting a collection of these objects from the parent object, or removing the parent object (cascade-delete is on). I've included my primary key class and the relevant parts of the object's bean class, the parent's bean class, and the allocation backtrace from OptimizeIt. Can anyone tell me what I'm doing wrong?
      Thanks in advance,

      Ben

      The Primary Key class:

      package com.mc123.ejb.device;

      public class DigitalInputPK implements java.io.Serializable {

      public int devId;
      public int index;


      public DigitalInputPK () {
      }

      public DigitalInputPK (int devId, int index) {
      this.devId = devId;
      this.index = index;
      }

      public int getDevId() {
      return devId;
      }

      public int getIndex () {
      return index;
      }

      public boolean equals (Object obj) {
      if (obj == null
      || !(obj instanceof DigitalInputPK)) {
      return false;
      }

      DigitalInputPK other = (DigitalInputPK)obj;

      if (this.devId == other.devId
      && this.index == other.index) {
      return true;
      } else {
      return false;
      }
      }

      public int hashCode () {
      StringBuffer str = new StringBuffer();
      str.append(devId);
      str.append("|");
      str.append(index);

      return str.toString().hashCode();
      }

      public String toString() {
      return "devId=" + devId + ", index=" + index;
      }
      }


      the Object's Bean:
      package com.mc123.ejb.device;

      import javax.ejb.EntityContext;
      import javax.ejb.CreateException;

      public abstract class DigitalInputBean implements javax.ejb.EntityBean
      {
      public DigitalInputPK ejbCreate (String label, int index, DeviceLocal device)
      throws CreateException {
      setDevId(((Integer)device.getPrimaryKey()).intValue());
      setLabel(label);
      setIndex(index);
      return null;
      }

      public void ejbPostCreate(String label, int index, DeviceLocal device) {
      setDevice(device);
      }

      // persistent fields
      public abstract Integer getId();
      public abstract void setId (Integer id);

      // These two are for the compound primary key (dev_id, index) to constrain DigitalInputs.
      public abstract int getDevId ();
      public abstract void setDevId (int devId);

      public abstract int getIndex ();
      public abstract void setIndex (int index);

      public abstract String getLabel ();
      public abstract void setLabel (String label);

      public abstract boolean getIsOn ();
      public abstract void setIsOn (boolean isOn);

      public abstract boolean getIsFault ();
      public abstract void setIsFault (boolean isFault);

      //CMR fields
      public abstract DeviceLocal getDevice ();
      public abstract void setDevice (DeviceLocal device);

      // standard call back methods

      public void setEntityContext(EntityContext ec){}
      public void unsetEntityContext(){}
      public void ejbLoad(){}
      public void ejbStore(){}
      public void ejbActivate(){}
      public void ejbPassivate(){}
      public void ejbRemove(){}

      }

      the parent Bean's relevant methods:


      public abstract void setDigitalInputs (Collection inputs);
      public abstract Collection getDigitalInputs ();

      public DigitalInputDO[] getDigitalInputArray () {
      DigitalInputDO[] result = new DigitalInputDO[8];
      Collection inputs = getDigitalInputs();
      Iterator inputIter = inputs.iterator();
      while (inputIter.hasNext()) {
      DigitalInputLocal input = (DigitalInputLocal)inputIter.next();
      String label = input.getLabel();
      boolean isOn = input.getIsOn();
      boolean isFault = input.getIsFault();
      int index = input.getIndex();
      result[index] = new DigitalInputDO(getId().intValue(), index, label, isOn, isFault);
      }

      return result;
      }



      the Allocation Backtrace (notice the getDigitalInputArray method is called from the getStateData() method):

      18Kb of com.mc123.ejb.device.DigitalInputPK allocated since last mark.
      85.41% com.mc123.server.device.UpdateThread.run() (starting in UpdateThread.java:88)
      85.41% com.mc123.server.device.UpdateThread.handleDeviceInput() (starting in UpdateThread.java:113)
      85.41% com.mc123.server.device.JBossUpdateProxy.handleDeviceMessage() (starting in JBossUpdateProxy.java:157)
      85.41% com.mc123.server.device.DeviceMessage.processBinaryMessage() (starting in DeviceMessage.java:65)
      81.94% $Proxy60.getStateData()
      81.94% org.jboss.proxy.ClientContainer.invoke() (starting in ClientContainer.java:62)
      81.94% org.jboss.proxy.ejb.EntityInterceptor.invoke() (starting in EntityInterceptor.java:66)
      81.94% org.jboss.proxy.SecurityInterceptor.invoke() (starting in SecurityInterceptor.java:74)
      81.94% org.jboss.proxy.TransactionInterceptor.invoke() (starting in TransactionInterceptor.java:72)
      81.94% org.jboss.invocation.InvokerInterceptor.invoke() (starting in InvokerInterceptor.java:99)
      81.94% org.jboss.invocation.local.LocalInvoker.invoke() (starting in LocalInvoker.java:91)
      81.94% org.jboss.mx.server.MBeanServerImpl.invoke() (starting in MBeanServerImpl.java:506)
      81.94% org.jboss.ejb.EntityContainer.invoke() (starting in EntityContainer.java:1038)
      81.94% org.jboss.ejb.Container.invoke() (starting in Container.java:672)
      81.94% org.jboss.ejb.EntityContainer.invoke() (starting in EntityContainer.java:493)
      81.94% org.jboss.ejb.plugins.LogInterceptor.invoke() (starting in LogInterceptor.java:157)
      81.94% org.jboss.ejb.plugins.SecurityInterceptor.invoke() (starting in SecurityInterceptor.java:119)
      81.94% org.jboss.ejb.plugins.TxInterceptorCMT.invoke() (starting in TxInterceptorCMT.java:60)
      81.94% org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions() (starting in TxInterceptorCMT.java:123)
      81.94% org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext() (starting in AbstractTxInterceptor.java:102)
      81.94% org.jboss.ejb.plugins.EntityCreationInterceptor.invoke() (starting in EntityCreationInterceptor.java:69)
      81.94% org.jboss.ejb.plugins.EntityLockInterceptor.invoke() (starting in EntityLockInterceptor.java:88)
      81.94% org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke() (starting in EntityInstanceInterceptor.java:119)
      81.94% org.jboss.ejb.plugins.EntityReentranceInterceptor.invoke() (starting in EntityReentranceInterceptor.java:61)
      81.94% org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke() (starting in CachedConnectionInterceptor.java:182)
      81.94% org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke() (starting in EntitySynchronizationInterceptor.java:240)
      81.94% org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.invoke() (starting in JDBCRelationInterceptor.java:87)
      81.94% org.jboss.ejb.EntityContainer$ContainerInterceptor.invoke() (starting in EntityContainer.java:1160)
      81.94% sun.reflect.DelegatingMethodAccessorImpl.invoke() (starting in DelegatingMethodAccessorImpl.java:25)
      77.77% sun.reflect.GeneratedMethodAccessor62.invoke()
      77.77% com.mc123.ejb.device.DeviceBean.getStateData() (starting in DeviceBean.java:38)
      77.77% com.mc123.ejb.device.DeviceBean.getDigitalInputArray() (starting in DeviceBean.java:117)
      77.77% com.mc123.ejb.device.DeviceBean$Proxy.getDigitalInputs() (implemented in )
      77.77% org.jboss.proxy.compiler.Runtime.invoke() (starting in Runtime.java:59)
      77.77% org.jboss.ejb.plugins.cmp.bridge.EntityBridgeInvocationHandler.invoke() (starting in EntityBridgeInvocationHandler.java:81)
      77.77% org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.getValue() (starting in JDBCCMRFieldBridge.java:465)
      77.77% org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.getInstanceValue() (starting in JDBCCMRFieldBridge.java:491)
      77.77% org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.load() (starting in JDBCCMRFieldBridge.java:813)
      77.77% org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.loadRelation() (starting in JDBCStoreManager.java:643)
      77.77% org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadRelationCommand.execute() (starting in JDBCLoadRelationCommand.java:55)
      77.77% org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.loadPrimaryKeyResults() (starting in JDBCAbstractCMPFieldBridge.java:325)
      77.77% org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.setPrimaryKeyValue() (starting in JDBCAbstractCMPFieldBridge.java:198)
      77.77% sun.reflect.GeneratedConstructorAccessor54.newInstance()


      another Memory Allocation backtrace (this time showing that, when remove() is called, the instance was created):

      14.58% org.mortbay.util.ThreadPool$JobRunner.run() (starting in ThreadPool.java:658)
      14.58% org.mortbay.util.ThreadedServer.handle() (starting in ThreadedServer.java:291)
      14.58% org.mortbay.http.SocketListener.handleConnection() (starting in SocketListener.java:177)
      14.58% org.mortbay.http.HttpConnection.handle() (starting in HttpConnection.java:801)
      14.58% org.mortbay.http.HttpConnection.handleNext() (starting in HttpConnection.java:850)
      14.58% org.mortbay.http.HttpConnection.service() (starting in HttpConnection.java:783)
      14.58% org.jboss.jetty.Jetty.service() (starting in Jetty.java:541)
      14.58% org.mortbay.http.HttpServer.service() (starting in HttpServer.java:840)
      14.58% org.mortbay.http.HttpContext.handle() (starting in HttpContext.java:1568)
      14.58% org.mortbay.jetty.servlet.WebApplicationContext.handle() (starting in WebApplicationContext.java:540)
      14.58% org.mortbay.http.HttpContext.handle() (starting in HttpContext.java:1652)
      14.58% org.mortbay.jetty.servlet.ServletHandler.handle() (starting in ServletHandler.java:514)
      14.58% org.mortbay.jetty.servlet.WebApplicationHandler.dispatch() (starting in WebApplicationHandler.java:192)
      14.58% org.mortbay.jetty.servlet.ServletHolder.handle() (starting in ServletHolder.java:334)
      14.58% javax.servlet.http.HttpServlet.service() (starting in HttpServlet.java:848)
      14.58% javax.servlet.http.HttpServlet.service() (starting in HttpServlet.java:733)
      14.58% org.junitee.servlet.JUnitEEServlet.doGet() (starting in JUnitEEServlet.java:109)
      14.58% org.junitee.servlet.JUnitEEServlet.runTests() (starting in JUnitEEServlet.java:205)
      14.58% org.junitee.runner.TestRunner.run() (starting in TestRunner.java:62)
      14.58% org.junitee.runner.TestRunner$1.run() (starting in TestRunner.java:65)
      14.58% junit.framework.TestSuite.run() (starting in TestSuite.java:199)
      14.58% junit.framework.TestSuite.runTest() (starting in TestSuite.java:208)
      14.58% junit.framework.TestCase.run() (starting in TestCase.java:118)
      14.58% junit.framework.TestResult.run() (starting in TestResult.java:103)
      14.58% junit.framework.TestResult.runProtected() (starting in TestResult.java:124)
      14.58% junit.framework.TestResult$1.protect() (starting in TestResult.java:106)
      14.58% junit.framework.TestCase.runBare() (starting in TestCase.java:125)
      12.5% com.mc123.ejb.device.DeviceBeanTester.tearDown() (starting in DeviceBeanTester.java:76)
      6.25% $Proxy61.remove()
      6.25% org.jboss.ejb.plugins.local.EntityProxy.invoke() (starting in EntityProxy.java:31)
      6.25% org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invoke() (starting in BaseLocalContainerInvoker.java:293)
      6.25% org.jboss.ejb.EntityContainer.invoke() (starting in EntityContainer.java:493)
      6.25% org.jboss.ejb.plugins.LogInterceptor.invoke() (starting in LogInterceptor.java:157)
      6.25% org.jboss.ejb.plugins.SecurityInterceptor.invoke() (starting in SecurityInterceptor.java:119)
      6.25% org.jboss.ejb.plugins.TxInterceptorCMT.invoke() (starting in TxInterceptorCMT.java:60)
      6.25% org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions() (starting in TxInterceptorCMT.java:123)
      6.25% org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext() (starting in AbstractTxInterceptor.java:102)
      6.25% org.jboss.ejb.plugins.EntityCreationInterceptor.invoke() (starting in EntityCreationInterceptor.java:69)
      6.25% org.jboss.ejb.plugins.EntityLockInterceptor.invoke() (starting in EntityLockInterceptor.java:88)
      6.25% org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke() (starting in EntityInstanceInterceptor.java:119)
      6.25% org.jboss.ejb.plugins.EntityReentranceInterceptor.invoke() (starting in EntityReentranceInterceptor.java:61)
      6.25% org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke() (starting in CachedConnectionInterceptor.java:182)
      6.25% org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke() (starting in EntitySynchronizationInterceptor.java:240)
      6.25% org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.invoke() (starting in JDBCRelationInterceptor.java:87)
      6.25% org.jboss.ejb.EntityContainer$ContainerInterceptor.invoke() (starting in EntityContainer.java:1160)
      6.25% sun.reflect.DelegatingMethodAccessorImpl.invoke() (starting in DelegatingMethodAccessorImpl.java:25)
      5.55% sun.reflect.GeneratedMethodAccessor79.invoke()
      0.69% sun.reflect.NativeMethodAccessorImpl.invoke() (starting in NativeMethodAccessorImpl.java:27)

      ----------------------------------- 6.25% $Proxy60.remove()
      6.25% org.jboss.proxy.ClientContainer.invoke() (starting in ClientContainer.java:62)
      6.25% org.jboss.proxy.ejb.EntityInterceptor.invoke() (starting in EntityInterceptor.java:66)
      6.25% org.jboss.proxy.SecurityInterceptor.invoke() (starting in SecurityInterceptor.java:74)
      6.25% org.jboss.proxy.TransactionInterceptor.invoke() (starting in TransactionInterceptor.java:72)
      6.25% org.jboss.invocation.InvokerInterceptor.invoke() (starting in InvokerInterceptor.java:99)
      6.25% org.jboss.invocation.local.LocalInvoker.invoke() (starting in LocalInvoker.java:91)
      6.25% org.jboss.mx.server.MBeanServerImpl.invoke() (starting in MBeanServerImpl.java:506)
      6.25% org.jboss.ejb.EntityContainer.invoke() (starting in EntityContainer.java:1038)
      6.25% org.jboss.ejb.Container.invoke() (starting in Container.java:672)
      6.25% org.jboss.ejb.EntityContainer.invoke() (starting in EntityContainer.java:493)
      6.25% org.jboss.ejb.plugins.LogInterceptor.invoke() (starting in LogInterceptor.java:157)
      6.25% org.jboss.ejb.plugins.SecurityInterceptor.invoke() (starting in SecurityInterceptor.java:119)
      6.25% org.jboss.ejb.plugins.TxInterceptorCMT.invoke() (starting in TxInterceptorCMT.java:60)
      6.25% org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions() (starting in TxInterceptorCMT.java:123)
      6.25% org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext() (starting in AbstractTxInterceptor.java:102)
      6.25% org.jboss.ejb.plugins.EntityCreationInterceptor.invoke() (starting in EntityCreationInterceptor.java:69)
      6.25% org.jboss.ejb.plugins.EntityLockInterceptor.invoke() (starting in EntityLockInterceptor.java:88)
      6.25% org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke() (starting in EntityInstanceInterceptor.java:119)
      6.25% org.jboss.ejb.plugins.EntityReentranceInterceptor.invoke() (starting in EntityReentranceInterceptor.java:61)
      6.25% org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke() (starting in CachedConnectionInterceptor.java:182)
      6.25% org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke() (starting in EntitySynchronizationInterceptor.java:240)
      6.25% org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.invoke() (starting in JDBCRelationInterceptor.java:87)
      6.25% org.jboss.ejb.EntityContainer$ContainerInterceptor.invoke() (starting in EntityContainer.java:1160)
      6.25% sun.reflect.DelegatingMethodAccessorImpl.invoke() (starting in DelegatingMethodAccessorImpl.java:25)
      6.25% sun.reflect.GeneratedMethodAccessor79.invoke()
      6.25% org.jboss.ejb.EntityContainer.remove() (starting in EntityContainer.java:503)
      6.25% org.jboss.resource.connectionmanager.CachedConnectionInterceptor.removeEntity() (starting in CachedConnectionInterceptor.java:431)
      6.25% org.jboss.ejb.plugins.CMPPersistenceManager.removeEntity() (starting in CMPPersistenceManager.java:509)
      6.25% org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.removeEntity() (starting in JDBCStoreManager.java:635)
      6.25% org.jboss.ejb.plugins.cmp.jdbc.JDBCRemoveEntityCommand.execute() (starting in JDBCRemoveEntityCommand.java:70)
      6.25% org.jboss.ejb.plugins.cmp.jdbc.JDBCRemoveEntityCommand.removeFromRelations() (starting in JDBCRemoveEntityCommand.java:124)
      6.25% org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.getInstanceValue() (starting in JDBCCMRFieldBridge.java:491)
      6.25% org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.load() (starting in JDBCCMRFieldBridge.java:813)
      6.25% org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.loadRelation() (starting in JDBCStoreManager.java:643)
      6.25% org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadRelationCommand.execute() (starting in JDBCLoadRelationCommand.java:55)
      6.25% org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.loadPrimaryKeyResults() (starting in JDBCAbstractCMPFieldBridge.java:325)
      6.25% org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.setPrimaryKeyValue() (starting in JDBCAbstractCMPFieldBridge.java:198)
      6.25% sun.reflect.GeneratedConstructorAccessor54.newInstance()
      2.08% junit.framework.TestCase.runTest() (starting in TestCase.java:138)
      2.08% sun.reflect.DelegatingMethodAccessorImpl.invoke() (starting in DelegatingMethodAccessorImpl.java:25)
      2.08% sun.reflect.NativeMethodAccessorImpl.invoke() (starting in NativeMethodAccessorImpl.java:27)