Archived

This forum has been archived. Please start a new discussion on GitHub.

Memory problem using dictionary or array as parameters

Hi all,
we have encountered a problem using dictionary or array as parameters.

We wrote a stress test with a client in C++ and a client in php.

Our slice definition is:
...
dictionary<string, string> mapArray;
...
interface Framework
      {
        bool query(mapArray arrayConfig, string stringQuery, out recordSet myResult, out int recordNumber) throws MBException;
...

Our Server.cpp is:
class FMKServer : public Ice::Application
{
public:

    virtual int run(int, char*[]);
};

int main(int argc, char* argv[])
{
    FMKServer app;
    return app.main(argc, argv, "config");
}

int FMKServer::run(int argc, char* argv[])
{
    Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("Framework");
    adapter->add(new FrameworkI, Ice::stringToIdentity("framework"));
    adapter->activate();
    communicator()->waitForShutdown();
    return EXIT_SUCCESS;
}


Our implementation of FrameworkI.cpp is:
bool FrameworkI::query(const mapArray& arrayConfig, const string& stringQuery, recordSet& myResult, int& recordNumber, const Ice::Current&) throw (MBException)
{
        IceUtil::Mutex::Lock lock(this->_mutex);

        mapArray arrayTemp=arrayConfig;
    
        Database db (arrayTemp["host"].c_str(),arrayTemp["loginDb"].c_str(),arrayTemp["passwordDb"].c_str(),arrayTemp["port"].c_str(),arrayTemp["dbName"].c_str(),arrayTemp["databaseType"].c_str());
        try
        {
                db.query(stringQuery, myResult, recordNumber);
        }
        catch(exception ex)
        {
                cout << ex.what() << endl;
                MBException mbe;
                mbe.description=(string) ex.what();
                mbe.class="Database";
                mbe.method="query()";
                throw mbe;
        }
        arrayTemp.clear();
        return true;
};


At the moment, our method Database::query is empty and only returns true.

Calling the method many times in a cycle, we are seeing an incredibile growth of memory usage. The growht is directly proportional to the size of the dictionary as parameter. We tried also to replace the dictionary with a simple array. The problem was the same.
After the test, the occupied memory never decreases.
What's wrong?
Thanks in advance for your time.
Best regards,
Enrico

P.S. We are using:
Ice-3.0.1 patched
gcc-4.0.3
libstlport4.6
Debian testing

Comments

  • mes
    mes California
    Hi,

    Do you see the memory growing in the PHP client or the C++ server?

    Take care,
    - Mark
  • Hi Mark,

    thank you for your fast reply.

    We see the memory growing in the C++ Server either using a C++ client or using a php client.
    We inspect memory usage with top command.

    Thanks & bye
  • mes
    mes California
    Hi,

    I haven't been able to reproduce a leak by sending a dictionary<string, string> to a server. If you can provide a small but complete example that demonstrates the problem, we'll take a look at it.

    Take care,
    - Mark
  • Hi,

    this is the mini-example of our project.

    Thanks a lot.
  • Hi Mark,

    we got it!!!

    Thanks to Valgrind we found the problem.
    The Debian packaging of libstdc++6-4.0-dev had a memory leak problem.
    Upgrading this to a newer version and recompiling Ice-3.0.1 and our project, the problem was solved.

    Thanks again for your time.

    Best regards,
    Enrico
  • mes
    mes California
    Hi Enrico,

    I looked at your code and didn't see anything wrong. My next suggestion would have been to use a leak-checking tool like Purify. I'm glad to hear you've solved the problem.

    Take care,
    - Mark