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. VLD output error
Forum Updated to NodeBB v4.3 + New Features

VLD output error

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 559 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.
  • H Offline
    H Offline
    Haoxinn
    wrote on 15 Apr 2021, 11:07 last edited by
    #1

    Hello all,

    I use Qt to load two images and then call a image processing function. When I use Visual Leak Detector to check my code, the output of the tool is really strange. It indicates the largest number of used storage is GB, and it seems that I didn't call the function findItems() and processedPendingEvents().

    Below is the output of VLD and part of my code.
    Thx!

    part of the output of VLD tool: (It seems that function findItems() and processedPendingEvents() use large amount of storage?)

    WARNTING: Visual Leak Detector detected memory leaks !
    ---- Block 57 at 0x0000000005388730: 16 bytes ----
    Leak Hash: 0xD44F8893, Count: 1, Total 16 bytes
    Call Stack (TID 6752) :
    ucrtbased. dll!malloc ()
    f:\dd\vctools\crt\vcstartup\src\heap\new_scalar. cpp (19): camera. exe!operator new() + 0xA bytes
    d:\shx\test\camera\mainwindow. cpp(421): camera. exe!MainWindow: :ShowNV21() + 0xA bytes
    d:\shx\test\camera\mainwindow. cpp (407): camera. exe !MainWindow: : ShowNV21()
    d:\shx\test\camera\mainwindow. cpp (59): camera. exe!MainWindow: getfile10()
    d:\shx\test\camera\debug\moc_mainwindow. cpp (82): camera. exe!MainWindow::qt_static_metacall() + 0xA bytes 
    Qt5Cored. dll!QStateMachinePrivate::processedPendingEvents() + 0x524D4D bytes
    Qt5Cored. dll!QStatellachinePrivate::processedPendingEvents() + 0x512521 bytes
    Qt5Widgetsd. dll!QTreeWidget::findItems() + 0x22DE48 bytes
    Qt5Widgetsd. dll!QTreeWidget::findItems()  + 0x23009A bytes
    Qt5Widgetsd. dll!QTreeWidget::findItems()  + 0x22F06A bytes
    Qt5Widgetsd. dll!QTreeWidget::findItems() + 0x22E637 bytes
    Qt5Widgetsd. dll!QTreeWidget::findItems() + OxB1015 bytes
    
    Largest number used: 60004904 bytes.
    Total allocations: 90489954 bytes.
    

    part of my code: (I know that I didn't delete scene in ShowNV21(), but after I correct it, the largest number used shown in VLD is still very large)

    void MainWindow::getfile10()  
    {
    
        QString OpenFile;
        int Width = 0, Height = 0;
    
        OpenFile = QFileDialog::getOpenFileName(this,
            "please choose an image file",
            "",
            "Image Files(*.nv21 *.bmp);;All(*.*)");
        if (OpenFile != "")
        {
            char *File_Path = (char *)malloc(OpenFile.toStdString().length());
            strcpy(File_Path, OpenFile.toStdString().c_str());
            ShowNV21(File_Path, ui->graphicsView_27);
    
            GetNV21Size(OpenFile.toStdString().c_str(), &Width, &Height);
            ui->lineEdit_52->setText(QString::number(Width));
            ui->lineEdit_53->setText(QString::number(Height));
    
            imgNum = 2;
            Img_Info[0].Width = Width;
            Img_Info[0].Height = Height;
            Img_Info[0].File_Path = File_Path;
    
        }
    
    }
    
    oid MainWindow::ShowNV21(const char *File_Path, QGraphicsView *graphicsView)
    {
        int Width, Height;
        GetNV21Size(File_Path, &Width, &Height);
        MainWindow::ShowNV21(File_Path, graphicsView, Width, Height);
    }
    
    void MainWindow::ShowNV21(const char *File_Path, QGraphicsView *graphicsView, unsigned int Width, unsigned int Height)
    {
        unsigned char *NV21_Img= (unsigned char *)malloc(Width * Width * 3 / 2);
        unsigned char *RBG_Img = (unsigned char *)malloc(Width * Height * 3);
    
        FILE *Img = fopen(File_Path, "rb");
        fread(NV21_Img, Width * Width * 3 / 2, 1, Img);
        fclose(Img);
    
        NV21_T_RGB(Width, Height, NV21_Img, RBG_Img);
        QImage Original_Imag = QImage(RBG_Img, Width, Height, QImage::Format_RGB888);
        QImage Scaled_Img = Original_Imag.scaled(graphicsView->width(), graphicsView->height());
        QGraphicsScene *scene = new QGraphicsScene;
        scene->addPixmap(QPixmap::fromImage(Scaled_Img));
        graphicsView->setScene(scene);
        graphicsView->show();
    
        free(NV21_Img);
        free(RBG_Img);
    }
    
    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 15 Apr 2021, 11:13 last edited by
      #2

      @Haoxinn said in VLD output error:

      File_Path

      C(++) basic - when you allocate something you have to deallocate it later on.
      Don't use c constructs in C++ code. It just gives you problems (like e.g. forgetting about the deallocation).

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      H 1 Reply Last reply 15 Apr 2021, 13:10
      3
      • C Christian Ehrlicher
        15 Apr 2021, 11:13

        @Haoxinn said in VLD output error:

        File_Path

        C(++) basic - when you allocate something you have to deallocate it later on.
        Don't use c constructs in C++ code. It just gives you problems (like e.g. forgetting about the deallocation).

        H Offline
        H Offline
        Haoxinn
        wrote on 15 Apr 2021, 13:10 last edited by
        #3

        @Christian-Ehrlicher Thanks for your kindly reply! You mean I should use keywords new and delete to allocate the storage, rather than C function malloc() and free() ?

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 15 Apr 2021, 13:14 last edited by
          #4

          No, you should use proper container like e.g. std::vector or std::string since the deallocation is done automatically in the dtor of those classes.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          H 1 Reply Last reply 16 Apr 2021, 01:51
          1
          • C Christian Ehrlicher
            15 Apr 2021, 13:14

            No, you should use proper container like e.g. std::vector or std::string since the deallocation is done automatically in the dtor of those classes.

            H Offline
            H Offline
            Haoxinn
            wrote on 16 Apr 2021, 01:51 last edited by
            #5

            @Christian-Ehrlicher Ohhhhh! It works! I replaced all the function malloc() in my code, then the output of VLD went back to a normal value. THANKS A LOT!!!

            1 Reply Last reply
            0

            1/5

            15 Apr 2021, 11:07

            • Login

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