Results 1 to 6 of 6

Thread: A strange statement in SSLEchoServer tutorial

  1. #1
    Join Date
    Dec 2015
    Location
    Rome
    Posts
    16
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows

    Question A strange statement in SSLEchoServer tutorial

    Ho to all,
    I seen the statement qDeleteAll(m_clients.begin(), m_clients.end()); at line 81 of SSLEchoServer.cpp file of SSEchoServer tutorial project
    (Qt\Examples\Qt-5.5\websockets\sslechoserver\sslechoserver.cpp).

    My dubt: why call an esplicitally delete all m_clients elements using qDeleteAll() if his destructor (m_clients's destructor) call itself?
    Commenting this line I did not seen memory leaks closing application with alive connections.

    Sorry for my English .
    Regards
    Giorgio

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: A strange statement in SSLEchoServer tutorial

    Quote Originally Posted by oop View Post
    My dubt: why call an esplicitally delete all m_clients elements using qDeleteAll() if his destructor (m_clients's destructor) call itself?
    The destructor of QList on a pointer type does not call delete on the pointers, so qDeleteAll() is needed if you want these objects to be deleted as well.

    Quote Originally Posted by oop View Post
    Commenting this line I did not seen memory leaks closing application with alive connections.
    If by "closing application" you mean that it exited, then the operating system will have reclaimed all resources associated with the process.

    Cheers,
    _

  3. #3
    Join Date
    Dec 2015
    Location
    Rome
    Posts
    16
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: A strange statement in SSLEchoServer tutorial

    Hi,
    yes you are right m_clients contains pointers to QWebSocket and they are handled and then destroyed by QWebSocketServer (I am supposing) not by m_clients (QList ) destructor.
    But thus the line I mentioned above ( qDeleteAll(m_clients.begin(),m_clients.end()) is not helpful. I can comment that line, close the application naturally (calling quit()) without memory leaks with or not the qDeleteAll(m_clients.begin(),m_clients.end());.

    Yes I think in this case, this line, is not helpful.
    I ask for better understand.


    Giorgio

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

    Default Re: A strange statement in SSLEchoServer tutorial

    Quote Originally Posted by oop View Post
    yes you are right m_clients contains pointers to QWebSocket and they are handled and then destroyed by QWebSocketServer (I am supposing)
    First rule of programming: don't make assumptions.
    Especially not ones that can be disproven by reading the documentation:
    Quote Originally Posted by QtDocs
    QWebSocketServer does not take ownership of the returned QWebSocket object. It is up to the caller to delete the object explicitly
    Quote Originally Posted by oop View Post
    But thus the line I mentioned above ( qDeleteAll(m_clients.begin(),m_clients.end()) is not helpful. I can comment that line, close the application naturally (calling quit()) without memory leaks with or not the qDeleteAll(m_clients.begin(),m_clients.end());.
    And how did you check that? Valgrind? Some other memory profiler?

    Cheers,
    _

  5. #5
    Join Date
    Dec 2015
    Location
    Rome
    Posts
    16
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: A strange statement in SSLEchoServer tutorial

    Hi, yes assumptions are dangerous.
    No I did read documentation, I simply seen that commenting that line no wrong behaviours happen in application execution also quitting it with alive connections.
    No, I did check in depth because my focus is at the moment at other thinks, I seen only no memory leaks reported from Visual Studio.

    At the moment I am testing and working without the above qDeleteAll() and it are working fine, though I keep in mind that line and keep ready to restore it if some problem or suspect happens.


    Sorry for my English.

    Cheers,
    Giorgio

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: A strange statement in SSLEchoServer tutorial

    Quote Originally Posted by oop View Post
    No I did read documentation, I simply seen that commenting that line no wrong behaviours happen in application execution also quitting it with alive connections.
    How do you know that the connections weren't closed to the application shutdown?

    Quote Originally Posted by oop View Post
    No, I did check in depth because my focus is at the moment at other thinks, I seen only no memory leaks reported from Visual Studio.
    If you haven't investigated if that leads to leaks, how did you arrive at that conclusion?

    Quote Originally Posted by oop View Post
    At the moment I am testing and working without the above qDeleteAll() and it are working fine, though I keep in mind that line and keep ready to restore it if some problem or suspect happens.
    Why not just keep it as intended?

    Cheers,
    _

Similar Threads

  1. Return-statement with no value
    By Stanfillirenfro in forum Qt Programming
    Replies: 2
    Last Post: 18th January 2014, 19:29
  2. IF-Statement problem
    By ayanda83 in forum Newbie
    Replies: 2
    Last Post: 18th November 2013, 08:02
  3. Strange behavior of return statement
    By Raadush in forum Qt Programming
    Replies: 8
    Last Post: 11th October 2012, 10:31
  4. How to get value from a query statement ?
    By hohoanganh205 in forum Newbie
    Replies: 3
    Last Post: 5th January 2012, 14:23
  5. SmartFOSS Mission Statement
    By travlr in forum Qt-based Software
    Replies: 0
    Last Post: 16th April 2007, 05:41

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.