How to clean up memory in WT?

穿精又带淫゛_ 提交于 2019-12-23 17:13:40

问题


UPDATE 3/27/2013

It would appear that I am not leaking memory, it is just WT not keeping a persistent session every time F5 is hit, or a new user connects. Basically the old session gets deleted, and a new one is made every time F5 is hit, or a new user connects from another machine. I have read some parts of the documentation that mention making the session persistent, so when a user reloads the page, or a different user connects they all see the same content. However, I have not been able to get it working yet. I think it is a function call or a setting in the wt_config.xml file. Will update if I make any other progress.

ORIGINAL POST

So my question is, how do I clean up memory in WT so every time the user presses F5 on the page the memory use stays the same in the task manager?

Ok, so I am working with WT pronounced (witty) and I have noticed that my server application consumes more memory every time the user hits F5 on the page to refresh it, which to me looks like I am leaking memory, but I followed the same process as WT most basic applications...

So, I went back to the most basic WT app I could find, the hello application the code for which, and the working example, can be found here(http://www.webtoolkit.eu/wt/examples/) if you have not personally built the project.

Once I ran the example on my machine and hit F5 on the page, the memory in my task manager increased.

My likely suspect is this function below.

WApplication *createApplication(const WEnvironment& env)
{
  /*
  * You could read information from the environment to decide whether
  * the user has permission to start a new application
  */
  return new HelloApplication(env);
}

It gets called every time F5 is hit and makes a new instance of the HelloApplication which inherits from WApplication.

Some things I have tried to remedy the situation that have not worked include: Keeping 2 pointers for the HelloApplication so I can delete the old pointer every time a new one is allocated. Calling the quit() function, and deleting the pointer. Just calling the quit() function. I have also looked around on the WT documentation site(http://www.webtoolkit.eu/wt/doc/reference/html/index.html) for more detailed information on the class and it's methods, but have not come up with anything that worked.

I ask that anyone responding please be as detailed as possible in how to handle the cleanup of the memory. An example would be much appreciated, thanks in advance!


回答1:


The manual of WApplication says that you create it when the createApplication callback is called, and that Wt deletes it when quit is called, and when the session times out. The default session time-out is 10 minutes (wt_config.xml), so that may be the reason why your memory consumption grows initially when pressing F5.

http://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WApplication.html#details

Something different that explains what you see: memory consumption reported by the operating system is not a reliable method to determine if an application leaks memory since free does not really return the memory to the OS. Use proper memory checking tools, such as valgrind.




回答2:


You also must be aware of the fact that as of Wt 3.3.0 the sessions are only cleaned up as long as requests are received (see this reply of a Wt developer). To overcome this limitation the developer suggests using something similar to following code.

static bool terminating = false;

void
callRepeatedly(boost::function<void()> function, int seconds)
{
    if (!terminating) {
        Wt::WServer::instance()->ioService().schedule(
            seconds * 1000, boost::bind(callRepeatedly, function, seconds));
    }
    function();
}

int
main(int argc, char** argv)
{
    ...

    callRepeatedly(boost::bind(&Wt::WServer::expireSessions, &server), 60);
    Wt::WServer::waitForShutdown();
    terminating = true;
    server.stop();

    ...
}


来源:https://stackoverflow.com/questions/15116077/how-to-clean-up-memory-in-wt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!