Results 1 to 5 of 5

Thread: Memory Leaks

  1. #1
    Join Date
    May 2014
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Memory Leaks

    Hello.
    I'm trying to solve some memory leaks in my application. I noticed that when I allocate a object with the new operator (for example a QGLWidget) obviously the memory used by application increased, but when I tried to delete the object only a portion has been released. To better understand I tried a simple program like the following code:

    QList<QGLWidget *> aaa;
    int i;

    (1)
    for(i=0;i<100;i++)
    aaa.append(new QGLWidget());

    (2)
    for(i=0;i<100;i++)
    delete aaa.at(i);

    (3)
    The application memory usage at each point is the following: (1) 4672 K (2) 413156 K (3) 111212 K

    Why the deallocation isn't complete? In my original application I need to allocate and deallocate many times these objects but this situation brings a memory increase too high. I'm using Qt 4.8.4 in OpenSUSE 12.3. Can someone help me?? Thanks

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,734
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Memory Leaks

    Memory allocated to a process is not generally freed to the operating system immediately an object is deleted. Chances are the process will request a new allocation shortly and this will be filled from free memory already allocated to the process. This is why operating system tools, like the free command on Linux, are not particularly useful for identifying small leaks. All memory allocated to the process will be freed when the process is terminated.

    If you want to investigate memory leaks then use a tool built for the job, like Valgrind.

  3. #3
    Join Date
    May 2014
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Memory Leaks

    Thanks for your reply ChrisW67.
    The code above it's only an example. In my application I have to allocate/deallocate a QGLWidget several times. I know that the OS doesn't freed immediatly the memory, but in my application I noticed that the memory isn't deallocated also after many minutes. I need to reistantiate a QGLWidget when the user clicks on a particular button, this can happen 2-3 times per minute, so the OS would have all the time to freed the memory, but this doesn't happen; for each click the memory increases and after 1 hour of application usage the memory reaches 1 GB. I think to manage correctly the method where I implented the QGLWidget reinitialization, in fact, I performed an object DELETE before and a NEW after. What do I have to do in order to solve this issue??? Thanks.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Memory Leaks

    As ChrisW67 said, use a tool designed for finding leaks to actually locate the leak instead of guessing where the leak is.

    Cheers,
    _

  5. #5
    Join Date
    May 2014
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Memory Leaks

    I tried to use Valgrind but unfortunatly my application is very big and so when I've launched it with Valgrind it blocked because too heavy.

Similar Threads

  1. Memory leaks!
    By karlkar in forum Newbie
    Replies: 1
    Last Post: 28th June 2013, 22:37
  2. QT Memory Leaks
    By lukabratzi in forum Qt Programming
    Replies: 17
    Last Post: 28th February 2012, 20:01
  3. Memory Leaks
    By kaushal_gaurav in forum Qt Programming
    Replies: 4
    Last Post: 20th October 2008, 16:26
  4. Memory leaks..
    By santhoshv84 in forum Qt Programming
    Replies: 2
    Last Post: 28th August 2008, 19:28
  5. why there are memory leaks in Qt?
    By cocalele in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2006, 09:55

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.