Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QByteArray with new and delete
QtWS25 Last Chance

QByteArray with new and delete

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 554 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DungeonLords
    wrote on last edited by
    #1

    Does QByteArray free memory on it's own accord?
    QByteArray ba1(""); //create array

    MainWindow::~MainWindow()
    {
    //Need I delete ba1 in destructor?
    delete ba1;
    }

    I know that Qt auto destroy objects inherited of QObject and this objects has parents. But QByteArray is initialezed without parent setting, isn't it?

    jsulmJ 1 Reply Last reply
    0
    • D DungeonLords

      Does QByteArray free memory on it's own accord?
      QByteArray ba1(""); //create array

      MainWindow::~MainWindow()
      {
      //Need I delete ba1 in destructor?
      delete ba1;
      }

      I know that Qt auto destroy objects inherited of QObject and this objects has parents. But QByteArray is initialezed without parent setting, isn't it?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @DungeonLords said in QByteArray with new and delete:

      Does QByteArray free memory on it's own accord?

      Yes, it does as soon as it is destroyed.
      Also there is no need to delete stack allocated objects.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      JonBJ 1 Reply Last reply
      2
      • jsulmJ jsulm

        @DungeonLords said in QByteArray with new and delete:

        Does QByteArray free memory on it's own accord?

        Yes, it does as soon as it is destroyed.
        Also there is no need to delete stack allocated objects.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @jsulm said in QByteArray with new and delete:

        Also there is no need to delete stack allocated objects.

        Not only is there "no need", you must not delete stack objects (non-newed), as your code currently does --- doesn't it crash?

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved