Results 1 to 4 of 4

Thread: I need help detecting a memory leak

  1. #1
    Join Date
    Jun 2008
    Posts
    83
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default I need help detecting a memory leak

    Hi:

    I've written this program that does in general lines does the following.

    1) Defines this class Proc with a pointer to a generic class I've written called A (private variable in Proc.h declared as A *a).

    2) According to user input I need to crete a child (of A) Class B or C. Each of these classes contain a variation of a variable of the type QVector < QVector <qreal> > data . So the code for this creation (in a function inside a Proc object) goes like this: C *c = new C (parmeters); a = c;

    3) When the B or C classes are constructed data is initialized again according to user input.

    4) the actual process the program needs to run basically updates over and over again data in these classes (B or C) . However here (and not before this process begins) I notice a 20Mb (using the windows task administrator) increase of the memory consumed.

    5) After the updating process is done, the user might change a value. Then the program recreates the class deleting the previous implementation (the line here is simply delete a) and then creates a new C or B object. Then the updating process is run again but again I notice the 20Mb increase in memory.

    However here is what I don't get if all of the variables used by the function that does the updating are local.. how can the memory increase?

    I thought all local variables are automatically deleted (memory returned) when the function ends its execution.

    I would really appreaciate any help.

    Thanks

  2. #2
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: I need help detecting a memory leak

    Of course some code would be very helpful. Other than that, there is always Valgrind

  3. #3
    Join Date
    Jun 2008
    Posts
    83
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: I need help detecting a memory leak

    HI:

    Valgrind is no use in windows as far as I could tell. And I don't know squat about linux or the like to change my os because of this. But thanks anyway for the suggestion. Besides looking info I've read in an ubuntu forum that apparently Valgrind gives wrong info on Qt programs because of the way it manages memory.

    The problem with posting code is that it is too mcuh. But I´ll try to put up the parts that matter.

    On the mean time what is the proper way of deleting or destroying a variable of the QVector< QVector <qreal> > var, sort.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: I need help detecting a memory leak

    The increase of memory usage doesn't mean you have a leak. Try continuing the expansion until you reach the physical amount of memory in the machine and see if the usage continues to grow. Maybe the operating system is simply keeping the memory reserved for your process until some other process requests it. That's what Linux tends to do, by the way and it's perfectly fine. Maybe newer Windows systems do that as well.

Similar Threads

  1. Memory leak detection
    By Sid in forum Qt Programming
    Replies: 8
    Last Post: 4th May 2011, 22:38
  2. memory leak question
    By cool_qt in forum General Programming
    Replies: 3
    Last Post: 20th January 2009, 07:49
  3. Memory leak weirdness
    By Darhuuk in forum General Programming
    Replies: 10
    Last Post: 10th January 2008, 18:51
  4. QPixMap and Memory leak
    By Krish_ng in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 14:18
  5. Memory Leak in my Application :-(
    By Svaths in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2007, 19:42

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.