[SNMP4J] Memory Leak 1.5?

Frank Fock fock at agentpp.com
Tue May 10 21:20:14 CEST 2005


Hi glen,

There is no memory leak (at least none that shows this behavior).
Your code is also OK (although I wonder why you do not use
the SNMP4J-Agent API instead of writing your own agent API).

May be you need to change (update) the JRE.

Best regards,
Frank

glen wrote:

> Hi,
>
> Using the 1.5 version of the snmp library - just doing simple test to 
> see how things work (don't know much about SNMP yet). Using some code 
> I found on this mail archive I knocked up a quick test agent which 
> sends back a string to any get request. However when I run the code 
> despite it doing effectively nothing  the memory usage just keeps on 
> increasing until the jvm runs out of memory (note memory starts 
> leaking as soon as the code is run without having received any messages).
>
> Is there something I have missed or is there an issue with this 
> version of the library?
>
> Using IBM jvm, details:
>
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1)
> Classic VM (build 1.4.1, J2RE 1.4.1 IBM build cxia321411-20030930 (JIT 
> enabled: jitc))
>
> Cheers,
>
> Glen
>
> The code I used is as follows :
>
> import java.util.*;
>
> import org.snmp4j.*;
> import org.snmp4j.smi.*;
>
> public class testsnmp
> {
>       public static class Handler implements org.snmp4j.CommandResponder
>       {
>               protected java.lang.String mAddress = null;
>               protected int mPort = 0;
>               protected java.lang.String mMyCommunityName = null;
>               protected org.snmp4j.TransportMapping mServerSocket = null;
>               protected org.snmp4j.Snmp mSNMP = null;
>
>               public Handler()
>               {
>               }
>
>               public void configure()
>               {
>                       mAddress = "10.12.141.16";
>                       mPort = 161;
>                       mMyCommunityName = "test";
>               }
>
>               public void start()
>               {
>                       try
>                       {
>                               mServerSocket = new 
> org.snmp4j.transport.DefaultUdpTransportMapping(new 
> org.snmp4j.smi.UdpAddress(java.net.InetAddress.getByName(mAddress), 
> mPort));
>                               mSNMP = new org.snmp4j.Snmp(mServerSocket);
>                               mSNMP.addCommandResponder(this);
>                               mServerSocket.listen();
>                       }
>                       catch (java.net.UnknownHostException vException)
>                       {
>                               System.out.println(vException);
>                       }
>                       catch (java.io.IOException vException)
>                       {
>                               System.out.println(vException);
>                       }
>               }
>
>
>               public synchronized void 
> processPdu(org.snmp4j.CommandResponderEvent aEvent)
>               {
>                       java.lang.String vCommunityName = new 
> java.lang.String(aEvent.getSecurityName());
>                       System.out.println("Community name " + 
> vCommunityName);
>                       org.snmp4j.PDU vPDU = aEvent.getPDU();
>                       if (vPDU == null)
>                       {
>                               System.out.println("Null pdu");
>                       }
>                       else
>                       {
>                               System.out.println("(rcv) " + 
> vPDU.toString());
>                               switch (vPDU.getType())
>                               {
>                                       case org.snmp4j.PDU.GET:
>                                       case org.snmp4j.PDU.GETNEXT:
>                                               break;
>                               }
>                               org.snmp4j.mp.StatusInformation 
> statusInformation = new org.snmp4j.mp.StatusInformation();
>                               org.snmp4j.mp.StateReference ref = 
> aEvent.getStateReference();
>                               try
>                               {
>                                       System.out.println("Sending 
> response");
>                                       vPDU.setType(PDU.RESPONSE);
>                                       vPDU.set( 0, new 
> VariableBinding( vPDU.get(0).getOid(), new OctetString("Test") ) );
>                                       
> aEvent.getMessageDispatcher().returnResponsePdu(aEvent.getMessageProcessingModel(), 
>
>                                                                           
> aEvent.getSecurityModel(), aEvent.getSecurityName(),
>                                                                           
> aEvent.getSecurityLevel(), vPDU, aEvent.getMaxSizeResponsePDU(), ref,
>                                                                           
> statusInformation);
>                               }
>                               catch (org.snmp4j.MessageException 
> vException)
>                               {
>                                       System.out.println(vException);
>                               }
>                       }
>               }
>       }
>
>       public static void main(String argv[])
>       {
>               Handler h = new Handler();
>               h.configure();
>               h.start();
>              /** Do nothing loop **/
>               while( true )
>               {
>                       synchronized(testsnmp.class)
>                       {
>                               try
>                               {
>                                       testsnmp.class.wait();
>                               }
>                               catch( Exception e )
>                               {
>                               }
>                       }
>               }
>       }
> }
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j
>





More information about the SNMP4J mailing list