object lifetime/ownership

Hello all,

I’ve just started using Snmp++ and Agent++ and have a couple of questions.

There doesn’t seem to be any mention of the lifetime/ownership of the objects in this library. In the example programs, I see lots of “new MibTable”, “new OctetStr”, etc. But I don’t see any deletes. Does the library handle the destruction of everything. For example, if I create a MibTable and add several OctetStr objects to it, when I delete the table, do all the OctetStr objects get deleted too? Otherwise, I would expect lots of memory leaks.

Are there any tutorial-style documents as an introduction to the library? I can see the example programs, but was wondering if there was anything more descriptive of the various classes etc. I realise that I’ve got this software for free, so I can’t expect too much. But it would be great if there was a bit of a description of each class and its purpose.

Finally, I want my program to act as an SNMP agent but don’t want the main program to block. All of the example programs loop forever at the bottom of main(). I want that loop to run in a sub-thread so my main() can go on and do other things. Is it just a matter of moving that while loop to the thread. Are there any synchronisation precautions that I need to take?

Thanks very much for this great software and for any answers to these questions.


Hi Graham,

As you guessed, the MibLeaf and MibTable objects are created by you and deleted when the Mib instance is deleted by its destructor. All the OctetStr and Integer32 etc. objects added to a MibTable of MibLeaf are deleted then as well.
Although the following tutorial is no longer up-to-date (it refers to version 2.x!), it might help you to understand the basic concepts:

You can of course run the main loop of the examples in a thread. That is OK. When you do updates from the main loop on the Mib object and its MibLeaf/MibTable objects then you should first lock the Mib and then the MibEntry that you modify. More details are explained here:

Hope that helps :slightly_smiling_face:

Best regards,

Thanks very much for your reply, Frank. That’s all very reassuring.