Home Help Center

Leak Warning - Why?

acbellacbell Member Andrew BellOrganization: Iowa State UniversityProject: National Resources Inventory ✭✭
Hi,

I've got an extremly simple service that complains of a leak when you terminate it with ctrl-c. Can someone please tell me what I am doing wrong?

Thanks:

Slice File:
module it
{
interface iti {
};
};

C++ Server Header:

#include <Ice/Service.h>
#include "it.h"

using namespace std;

namespace it
{
class Server : public virtual iti, public virtual Ice::Service
{
public:
Server()
{}

bool start(int argc, char *argv[]);
};
}

C++ Server Source:
#include "Server.h"

using namespace std;

int main(int argc, char *argv[])
{
it::Server *server = new it::Server();
return (server->main(argc, argv));
}

bool it::Server::start(int argc, char *argv[])
{
Ice::ObjectAdapterPtr adapt;

adapt = communicator()->createObjectAdapter("FooBar");
adapt->add(this, Ice::stringToIdentity("Foo"));
adapt->activate();

return (true);
}



If the line:

adapt = adapt->add(this, Ice::stringToIdentity("Foo"));

in it::Server::start() is removed, the error goes away. Is this my problem, or a problem in the framework?

Thanks,

-- Andrew Bell
[email protected]

Comments

  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Is it a warning from Ice or from a tool like Purify?

    Do you get a warning when you use separate classes/objects for your service and your servant?

    Also, it's always good to mention the Ice version and OS you're using.

    Cheers,
    Bernard
  • acbellacbell Member Andrew BellOrganization: Iowa State UniversityProject: National Resources Inventory ✭✭
    Leak Warning - Internal To Ice

    So sorry to have been unclear. The warning is coming from the Ice runtime. Using Ice Version 2.1.0 on Solaris with gcc:

    $ Itc
    ^CItc: warning: The communicator is not the last Ice object that is
    deleted. (You can disable this warning by setting the
    property `Ice.Warn.Leaks' to 0.)
  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    it::Server *server = new it::Server();

    Here is your leak: you need to put this reference-counted object in a Ptr to delete it properly, e.g.:

    Ice::ServicePtr server = new it::Server();

    If the warning does not go away, please try using different objects for your service and your servant.

    Cheers,
    Bernard
  • acbellacbell Member Andrew BellOrganization: Iowa State UniversityProject: National Resources Inventory ✭✭
    Thanks

    Sorry I missed that. For anyone else reading this, Ice::ServicePtr isn't defined (at least in 2.1.0). The following typedef is needed (dropping the Ice namespace, of course):

    typedef ::IceInternal::Handle<it::Server> ServicePtr;

    -- Andrew Bell
    [email protected]
  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Sorry, there is no Ice::ServicePtr because Ice::Service is not reference-counted. You could also write:

    it::Server *server = new it::Server();
    Ice::ObjectPtr servant = server; // will release this object
    return (server->main(argc, argv));

    Cheers,
    Bernard
Sign In or Register to comment.