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. Qt Memory Deallocation
Forum Updated to NodeBB v4.3 + New Features

Qt Memory Deallocation

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.5k Views 1 Watching
  • 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.
  • Y Offline
    Y Offline
    yaseminyilmaz
    wrote on last edited by
    #1

    Hi all,

    I have a Qt program composed of objects dynamically created. These objects have derived from QObjects but not used parent argument at the constructor caller for example myQObject *mObject = new myQObject();

    Does Qt make the memory deallocation while QMainWindow has been closing or should we do delete operations such as C programmer?

    Thanks advance for your clarifications and helps,

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      If those objects do not have a parent, they won't be deleted automatically.

      1 Reply Last reply
      0
      • JeroentjehomeJ Offline
        JeroentjehomeJ Offline
        Jeroentjehome
        wrote on last edited by
        #3

        Lukas is right indeed, the objects will not be destroyed when classes aren't used anymore. Qt will clear all allocated memory when closing the program if you mean that.
        It is bad practice not to use the "parent" object to control the allocation/destruction of class memory. If you start writing larger programs you might even cause memory leaks! When using the new operator without the parent option always destroy the allocated memory. The only exception is the allocation in the Main class. This gets freed when the program closes.
        Greetz

        Greetz, Jeroen

        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