Page 3 of 5 FirstFirst 12345 LastLast
Results 21 to 30 of 44

Thread: Memory leaks

  1. #21
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,257
    Distro
    Kubuntu

    Re: Memory leaks

    hosseinyounesi -- Do you think you could possibly design your application in terms of objects? In other words, can you please put together an OO design, where you separate object data from object actions.

    You are allocating way too much more than you need.

    Also, think carefully about the following... what is the value of 'i' at this point in the code?
    Code:
    void * ProcessThread(void * arg)
    {
    
    while(true)
    {
    pthread_mutex_lock(&mutex[i]);
    
    pthread_mutex_lock(&data_mutex);
    Accepter=ti[i].Accepter;
    availableThreads.remove(i);
    pthread_mutex_unlock(&data_mutex);
    
    char* packet=NULL;
    char* Resp=NULL;
    char* respons=NULL;
    char **test=NULL;
    char logstr[100];
    XMLNode Response,xmlpacket;
    unsigned long size=0;
    int i=(int)arg;
    ...

  2. #22
    Join Date
    Jul 2008
    Beans
    95

    Re: Memory leaks

    Hi,

    I just copied the code, int i=(int)arg is in beginning of function. You thick that OO can help me about memory? Or just readability?

  3. #23
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,257
    Distro
    Kubuntu

    Re: Memory leaks

    Quote Originally Posted by hosseinyounesi View Post
    Hi,

    I just copied the code, int i=(int)arg is in beginning of function. You thick that OO can help me about memory? Or just readability?
    Readability is not only good for those who peer review your code, but ultimately it is good for the one developing the code.

    You could define a Thread Object that encapsulates many of the entities it requires, without having to allocate them, or should I say declare them, elsewhere. Keep your code simple, and it will be easier to manage.

    For grins and also for educational purposes, I have put together a TCP Server application that handles multiple client connections. The server maintains a pool of client handlers, that is uses to handle each client that connects. If all client handlers are in use, and another client connects, well then it is not serviced.

    Please take a look at the code, which I have attached. Note that the server depends on an external Socket Library, which I have also attached.

    Let me know if you have any questions, or suggestions on how to improve the code.
    Last edited by dwhitney67; October 30th, 2010 at 05:24 PM.

  4. #24
    Join Date
    Jul 2008
    Beans
    95

    Exclamation Re: Memory leaks - Mysql problem

    Hi again,

    I'm testing my code for large traffics, now after 3 days memory increasing is stopped (just increasing or decreasing 0.1 MB sometimes).
    Thanks for helps. But there is another problem! I'm using mysqlpp library, it works fine, but when there are too many connections it fails and this error appears:
    Access denied for user 'root'@'localhost' (using password: NO)
    This is my plan for each client connection: connect to mysql (with mysqlpp), execute some queries and close the mysql connection. What's wrong?
    Should I use persistent connection? open a connection and use it for all client connections and never close it?

    Thanks b4

  5. #25
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,257
    Distro
    Kubuntu

    Re: Memory leaks

    Read here about MySQL and the number of connections supported:
    http://dev.mysql.com/doc/refman/5.1/...nnections.html

    If you want to tweak the number of connections allowed, then I believe the appropriate file is /etc/mysql/my.cnf. Look for the 'max_connections' variable, which is probably commented out.

  6. #26
    Join Date
    Jul 2008
    Beans
    95

    Re: Memory leaks

    I'm not sure that it's because of MAX_CONNECTION. I increased max_connection and thread_concurrency. Nothing improved
    Any other parameter?

    Thanks

  7. #27
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,257
    Distro
    Kubuntu

    Re: Memory leaks

    Sorry for asking the obvious, but did you restart the MySQL server after making the configuration updates?

  8. #28
    Join Date
    Jul 2008
    Beans
    95

    Re: Memory leaks

    Yes i did
    I'll ask my question in mysql++ forum and I'll report the result here.

    Thanks again for your helps

  9. #29
    Join Date
    Jul 2008
    Beans
    95

    Re: Memory leaks

    "Segmentation fault" ! This is the new exception from m program. After running for more than 5 days, the above error appeared. What's wrong? Nothing new happened in past days! How can I determine the "Segmentation fault" reason?

    Thanks b4

  10. #30
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,257
    Distro
    Kubuntu

    Re: Memory leaks

    Run you application with gdb (or ddd) and present it the core file. For example:
    Code:
    gdb theapp corefile
    The other alternative is to run it again using valgrind or gdb.

Page 3 of 5 FirstFirst 12345 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •