Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Deallocate memory to singleton class which access database ?
Qt 6.11 is out! See what's new in the release blog

Deallocate memory to singleton class which access database ?

Scheduled Pinned Locked Moved Solved C++ Gurus
35 Posts 5 Posters 24.6k 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.
  • KroMignonK KroMignon

    @Qt-embedded-developer said in Deallocate memory to singleton class which access database ?:

    i can not enable it like that because any change like that not allowed in my device.

    As @jsulm already wrote before, replace auto with the corresponding type:

    for(std::map<int,SqliteManagerBGSync*>::iterator it = sqliteManagerMap::begin(); it != sqliteManagerMap::end(); ++it)
    {
    ...
    }
    
    J.HilkJ Offline
    J.HilkJ Offline
    J.Hilk
    Moderators
    wrote on last edited by J.Hilk
    #26

    @KroMignon IIRC range based for loops is a c++11 feature in itself 🤔

    never mind, I think need a break!


    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    KroMignonK 1 Reply Last reply
    0
    • J.HilkJ J.Hilk

      @KroMignon IIRC range based for loops is a c++11 feature in itself 🤔

      never mind, I think need a break!

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #27

      @J-Hilk said in Deallocate memory to singleton class which access database ?:

      IIRC range based for loops is a c++11 feature in itself 🤔

      Are you sure? I don't believe that std::map<>::iterator support is comming with C++11.

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      jsulmJ 1 Reply Last reply
      0
      • KroMignonK KroMignon

        @J-Hilk said in Deallocate memory to singleton class which access database ?:

        IIRC range based for loops is a c++11 feature in itself 🤔

        Are you sure? I don't believe that std::map<>::iterator support is comming with C++11.

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

        @KroMignon I think @J-Hilk misunderstood your code: you are not using range based loop

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

        1 Reply Last reply
        1
        • KroMignonK KroMignon

          @Qt-embedded-developer said in Deallocate memory to singleton class which access database ?:

          i can not enable it like that because any change like that not allowed in my device.

          As @jsulm already wrote before, replace auto with the corresponding type:

          for(std::map<int,SqliteManagerBGSync*>::iterator it = sqliteManagerMap::begin(); it != sqliteManagerMap::end(); ++it)
          {
          ...
          }
          
          Q Offline
          Q Offline
          Qt embedded developer
          wrote on last edited by Qt embedded developer
          #29

          @KroMignon Here inside for loop i need to write

          for(std::map<int,SqliteManagerBGSync*>::iterator it = sqliteManagerMap::begin(); it != sqliteManagerMap::end(); ++it)
          {
          delete it;
          }
          
          

          or what i need to write to deallocate memory ?

          jsulmJ KroMignonK 2 Replies Last reply
          0
          • Q Qt embedded developer

            @KroMignon Here inside for loop i need to write

            for(std::map<int,SqliteManagerBGSync*>::iterator it = sqliteManagerMap::begin(); it != sqliteManagerMap::end(); ++it)
            {
            delete it;
            }
            
            

            or what i need to write to deallocate memory ?

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

            @Qt-embedded-developer said in Deallocate memory to singleton class which access database ?:

            delete it;

            delete it->second;

            of course

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

            1 Reply Last reply
            1
            • Q Qt embedded developer

              @KroMignon Here inside for loop i need to write

              for(std::map<int,SqliteManagerBGSync*>::iterator it = sqliteManagerMap::begin(); it != sqliteManagerMap::end(); ++it)
              {
              delete it;
              }
              
              

              or what i need to write to deallocate memory ?

              KroMignonK Offline
              KroMignonK Offline
              KroMignon
              wrote on last edited by KroMignon
              #31

              @Qt-embedded-developer said in Deallocate memory to singleton class which access database ?:

              or what i need to write to deallocate ?

              Please, take time to read std::map<> documentation.
              You are using a map iterator, so it is a container object which gives you access to key and value.

              delete it do not make sense!

              You want to delete the pointer hold in the value part: delete it->second

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              Q 1 Reply Last reply
              3
              • KroMignonK KroMignon

                @Qt-embedded-developer said in Deallocate memory to singleton class which access database ?:

                or what i need to write to deallocate ?

                Please, take time to read std::map<> documentation.
                You are using a map iterator, so it is a container object which gives you access to key and value.

                delete it do not make sense!

                You want to delete the pointer hold in the value part: delete it->second

                Q Offline
                Q Offline
                Qt embedded developer
                wrote on last edited by Qt embedded developer
                #32
                This post is deleted!
                1 Reply Last reply
                0
                • KroMignonK KroMignon

                  @Qt-embedded-developer said in Deallocate memory to singleton class which access database ?:

                  i can not enable it like that because any change like that not allowed in my device.

                  As @jsulm already wrote before, replace auto with the corresponding type:

                  for(std::map<int,SqliteManagerBGSync*>::iterator it = sqliteManagerMap::begin(); it != sqliteManagerMap::end(); ++it)
                  {
                  ...
                  }
                  
                  Q Offline
                  Q Offline
                  Qt embedded developer
                  wrote on last edited by
                  #33

                  @KroMignon Hi when i put sqliteManagerMap::begin() and sqliteManagerMap::end() i am getting error .

                  like below :

                  for(std::map<int,SqliteManagerBGSync *>::iterator it = sqliteManagerMap::begin(); it != sqliteManagerMap::end(); ++it)

                  but when i put sqliteManagerMap.begin() then i am getting no error.

                  jsulmJ KroMignonK 2 Replies Last reply
                  0
                  • Q Qt embedded developer

                    @KroMignon Hi when i put sqliteManagerMap::begin() and sqliteManagerMap::end() i am getting error .

                    like below :

                    for(std::map<int,SqliteManagerBGSync *>::iterator it = sqliteManagerMap::begin(); it != sqliteManagerMap::end(); ++it)

                    but when i put sqliteManagerMap.begin() then i am getting no error.

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

                    @Qt-embedded-developer said in Deallocate memory to singleton class which access database ?:

                    sqliteManagerMap::begin() and sqliteManagerMap::end()

                    As already explained in your other thread: begin() and end() are non-static methods, so you call them with . not :: !
                    Please learn C++ and read documentation!

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

                    1 Reply Last reply
                    1
                    • Q Qt embedded developer

                      @KroMignon Hi when i put sqliteManagerMap::begin() and sqliteManagerMap::end() i am getting error .

                      like below :

                      for(std::map<int,SqliteManagerBGSync *>::iterator it = sqliteManagerMap::begin(); it != sqliteManagerMap::end(); ++it)

                      but when i put sqliteManagerMap.begin() then i am getting no error.

                      KroMignonK Offline
                      KroMignonK Offline
                      KroMignon
                      wrote on last edited by
                      #35

                      @Qt-embedded-developer said in Deallocate memory to singleton class which access database ?:

                      for(std::map<int,SqliteManagerBGSync *>::iterator it = sqliteManagerMap::begin(); it != sqliteManagerMap::end(); ++it)

                      Sorry my fault, as @jsulm already told, this are not static class methods. You want to call class instance methode:

                      for(std::map<int,SqliteManagerBGSync *>::iterator it = sqliteManagerMap.begin(); it != sqliteManagerMap.end(); ++it)
                      

                      Was a long day yesterday!

                      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                      1 Reply Last reply
                      1

                      • Login

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