Results 1 to 10 of 10

Thread: Memory leaks with QDomElement::tagName()

  1. #1
    Join Date
    Sep 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Memory leaks with QDomElement::tagName()

    Hello,

    this is the scenario:
    - VStudio2005, using Qt4.7.2, built for VS2005 (dumpbin -imports on the Qt libs refering to VS80 libs)
    - I build another dll which links QtXml4.dll

    THIS method is creating memory leaks:

    Qt Code:
    1. int CTestClass::blubber( int iBlubber )
    2. {
    3. QDomElement aRoot;
    4. aRoot.tagName();
    5. return 0;
    6. }
    To copy to clipboard, switch view to plain text mode 

    and THE SAME method with commented tagName() is NOT creating memory leaks:
    Qt Code:
    1. int ARGOSXml_DomParser::blubber( int iBlubber )
    2. {
    3. QDomElement aRoot;
    4. // aRoot.tagName();
    5. return 0;
    6. }
    To copy to clipboard, switch view to plain text mode 

    NOTE: I do NOT call this method! just linking!

    I am really helpless... perhaps anyone got an idea!

    If you need more information, please ask!

    Any help is appreciated!
    saracaeus

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Memory leaks with QDomElement::tagName()

    How do you measure that it is a memory leak? I can't see it.

  3. #3
    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: Memory leaks with QDomElement::tagName()

    This is how this method is implemented:

    Qt Code:
    1. QString QDomElement::tagName() const
    2. {
    3. if (!impl)
    4. return QString();
    5. return impl->nodeName();
    6. }
    To copy to clipboard, switch view to plain text mode 
    I don't see where it could possibly leak memory.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Sep 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Memory leaks with QDomElement::tagName()

    well, thats exactly why I am helpless... I have no clue... the memory leaks coming from VS2005, this is the output:

    Qt Code:
    1. Detected memory leaks!
    2. Dumping objects ->
    3. {220} normal block at 0x012F4550, 24 bytes long.
    4. Data: < > 00 CD CD CD 00 00 00 00 00 00 00 00 00 00 00 00
    5. {219} normal block at 0x012F44F0, 32 bytes long.
    6. Data: < > 01 00 00 00 03 00 00 00 00 00 00 00 01 00 00 00
    7. {218} normal block at 0x012F44B0, 4 bytes long.
    8. Data: < D/ > F0 44 2F 01
    9. {217} normal block at 0x012F4458, 24 bytes long.
    10. Data: < > 00 CD CD CD 00 00 00 00 00 00 00 00 00 00 00 00
    11. {216} normal block at 0x012F4410, 12 bytes long.
    12. Data: <XD/ ;g ;g> 58 44 2F 01 C8 DD 3B 67 C8 DD 3B 67
    13. {215} normal block at 0x012F43B8, 24 bytes long.
    14. Data: < > 00 CD CD CD 00 00 00 00 00 00 00 00 00 00 00 00
    15. {214} normal block at 0x012F4370, 12 bytes long.
    16. Data: < C/ ;g ;g> B8 43 2F 01 C8 DD 3B 67 C8 DD 3B 67
    17. {213} normal block at 0x012F4318, 24 bytes long.
    18. Data: < > 00 CD CD CD 00 00 00 00 00 00 00 00 00 00 00 00
    19. {212} normal block at 0x012F42B8, 36 bytes long.
    20. Data: < C/ pC/ D/ > 18 43 2F 01 70 43 2F 01 10 44 2F 01 00 00 00 00
    21. {211} normal block at 0x012F4278, 4 bytes long.
    22. Data: < B/ > B8 42 2F 01
    23. {210} normal block at 0x012F4238, 4 bytes long.
    24. Data: < Y.g> A8 59 2E 67
    25. Object dump complete.
    26. The thread 'Win32 Thread' (0x814) has exited with code 0 (0x0).
    To copy to clipboard, switch view to plain text mode 

    And as I noted: the method is NOT even called!

    And once i comment this line, the memory leaks are gone!


  5. #5
    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: Memory leaks with QDomElement::tagName()

    When is that "leak" reported? If the method is not called, it can't possibly create a memory leak. If you have a leak then it is elsewhere.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Sep 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Memory leaks with QDomElement::tagName()

    The "leaks" are reported after the application is closed.

    It cant be elsewhere => if I comment this line, the leaks are gone!!!

    And of course a memory leak can happen w/o calling the method. Think about static objects etc. I dont have the Qt code, so I have no clue what is allocated and what not!

    I am not a dll-specialist on the other hand and it can be a runtime library problem. normally I like to use static links. So perhaps anyone got an idea about that.

    The same I have discovered with the QFile-constructor. Once i use it in a method, these memory leaks are there.


    Added after 9 minutes:


    I remember a similar problem:

    if a class has got a std::vector member and doesnt define a virtual destructor, then the vector is not free'd when the object is destroyed, because the vector's destructor isnt called, which is causing memory leaks!

    It might be somethin like that!

    As I said: I dont have the Qt-code and I am not familiar with it. So I hope there is somebody out there who got an idea
    Last edited by saracaeus; 20th February 2013 at 16:38.

  7. #7
    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: Memory leaks with QDomElement::tagName()

    Quote Originally Posted by saracaeus View Post
    It cant be elsewhere => if I comment this line, the leaks are gone!!!
    No, they are not gone. They are not being reported.

    And of course a memory leak can happen w/o calling the method. Think about static objects etc.
    With static objects a constructor is being called that can cause a memory leak.

    I dont have the Qt code, so I have no clue what is allocated and what not!
    I posted implementation of that method. There is no allocation there apart copying a string (which doesn't do any heap allocation).

    if a class has got a std::vector member and doesnt define a virtual destructor, then the vector is not free'd when the object is destroyed, because the vector's destructor isnt called, which is causing memory leaks!
    Well, this is not the case here. You are not constructing anything because you're not even calling any code.

    Again, there is no leak there.

    Does your reporting tool report a leak for this code?

    Qt Code:
    1. #include <QDomElement>
    2.  
    3. void func() {
    4. e.tagName();
    5. }
    6.  
    7. int main() { return 0; }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Sep 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Memory leaks with QDomElement::tagName()

    Following your suggestion I made another test: I created a new MFC application (I forgot to state this at the beginning, that I am using MFC). A blank MFC application from scratch doesnt produce memory leaks. Then I added this method again:

    Qt Code:
    1. void CTestProject2005Doc::Blubber( void )
    2. {
    3. e.tagName();
    4. }
    To copy to clipboard, switch view to plain text mode 

    First case: using MFC in a static library => NO MEMORY LEAKS
    Second case: using MFC in a dynamic library => MEMORY LEAKS

    So it must be a runtime library problem, but as I stated before, I am not a dll-specialist and thus dont have a clue why a dynamically linked MFC library together with a Qt-dll creates these memory leaks and a statically linked MFC library doesnt.

    So wherever the problem is, I hope that somebody has an idea to solve it

    Thank you in advance, whoever helps me!

  9. #9
    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: Memory leaks with QDomElement::tagName()

    There is no problem... You are experiencing a false positive.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Memory leaks with QDomElement::tagName()

    I have read that the reason for these apparent memory leaks is that the DLLs used in MFC are loaded at startup and unloaded at shutdown in a different order, so these "leaks" are the result of MFC objects that have not been deleted by the time the library is unloaded.

    I see this all the time. All I have to do is to declare an instance of the custom file browser we use in our apps (which is implemented in an MFC-based DLL), without actually invoking it, and I get thousands of lines of leaks reported on shutdown. You also see it when using MFC-based ActiveX controls.

    It is a real pain in the butt, because it makes finding real memory leaks so much harder when you have to wade through thousands of lines of nonsense to spot the one real report.

Similar Threads

  1. QT Memory Leaks
    By lukabratzi in forum Qt Programming
    Replies: 17
    Last Post: 28th February 2012, 21:01
  2. Memory Leaks
    By kaushal_gaurav in forum Qt Programming
    Replies: 4
    Last Post: 20th October 2008, 17:26
  3. Memory leaks..
    By santhoshv84 in forum Qt Programming
    Replies: 2
    Last Post: 28th August 2008, 20:28
  4. memory leaks
    By Fastman in forum Qt Programming
    Replies: 1
    Last Post: 5th March 2008, 09:00
  5. why there are memory leaks in Qt?
    By cocalele in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2006, 10:55

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.