Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to delete CStatic object.

How to delete CStatic object.

Scheduled Pinned Locked Moved C / C++ / MFC
14 Posts 5 Posters 0 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.
  • C Code o mat

    So you created a static like this: mystatic = new CStatis;, and deleted it like this: delete mystatis; and you get something like "the heap around whatever has been corrupted"?

    > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

    H Offline
    H Offline
    hemlat
    wrote on last edited by
    #5

    I have created member variable CStatic *m_myStatic;,I am allocating memory like this m_myStatic = new CStatic[m_filecount];,and I am deleting in destructor.It is showing breakpoint is due to corruption of heap.

    M C 2 Replies Last reply
    0
    • H hemlat

      I have created member variable CStatic *m_myStatic;,I am allocating memory like this m_myStatic = new CStatic[m_filecount];,and I am deleting in destructor.It is showing breakpoint is due to corruption of heap.

      M Offline
      M Offline
      Maximilien
      wrote on last edited by
      #6

      How are you deleting it ? like this : delete [] m_myStatic;

      This signature was proudly tested on animals.

      1 Reply Last reply
      0
      • H hemlat

        I have created member variable CStatic *m_myStatic;,I am allocating memory like this m_myStatic = new CStatic[m_filecount];,and I am deleting in destructor.It is showing breakpoint is due to corruption of heap.

        C Offline
        C Offline
        Code o mat
        wrote on last edited by
        #7

        I see, well, you need to delete an array -as Maximilien already pointed out- like this: delete []m_myStatic;. Otherwise, heap corruption can be caused by indexing out of your array, so you try to write items in the array which are not in the array at all, for example:

        int *int_array = new int[5];
        int_array[10] = 4;

        > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

        N 1 Reply Last reply
        0
        • C Code o mat

          I see, well, you need to delete an array -as Maximilien already pointed out- like this: delete []m_myStatic;. Otherwise, heap corruption can be caused by indexing out of your array, so you try to write items in the array which are not in the array at all, for example:

          int *int_array = new int[5];
          int_array[10] = 4;

          > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

          N Offline
          N Offline
          Niklas L
          wrote on last edited by
          #8

          This is not related at all. How you use an array has nothing to do with how you destroy it.

          home

          C 1 Reply Last reply
          0
          • N Niklas L

            This is not related at all. How you use an array has nothing to do with how you destroy it.

            home

            C Offline
            C Offline
            Code o mat
            wrote on last edited by
            #9

            He said he gets "corruption of heap", that -as far as i know- can be caused by what i said there. The question wasn't specifically "how to delete an array".

            > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

            D N 2 Replies Last reply
            0
            • C Code o mat

              He said he gets "corruption of heap", that -as far as i know- can be caused by what i said there. The question wasn't specifically "how to delete an array".

              > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #10

              Code-o-mat wrote:

              He said he gets "corruption of heap"...

              When he deletes, not accesses.

              "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              C 1 Reply Last reply
              0
              • C Code o mat

                He said he gets "corruption of heap", that -as far as i know- can be caused by what i said there. The question wasn't specifically "how to delete an array".

                > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

                N Offline
                N Offline
                Niklas L
                wrote on last edited by
                #11

                Lol! My bad! I was reading your 'Otherwise' as 'if you don't delete scalar you will get memory corruption'.

                home

                C 1 Reply Last reply
                0
                • D David Crow

                  Code-o-mat wrote:

                  He said he gets "corruption of heap"...

                  When he deletes, not accesses.

                  "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  C Offline
                  C Offline
                  Code o mat
                  wrote on last edited by
                  #12

                  Correct me when i am wrong but -at least in debug- when you allocate an array using new, the system will allocate somewhat more bytes than explicitly needed by your array and will place some special information infront and after your block. When you delete the array the system will check these special values infront and after the array and if it does not find what it expects it will complain about it because this probably means you wrote to memory you should not have written to. True, the example there was a bad one, i should have wrote int_array[5] = 4; instead of int_array[10] = 4;, because 10 is WAY after the lest element of the array...

                  > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

                  N 1 Reply Last reply
                  0
                  • N Niklas L

                    Lol! My bad! I was reading your 'Otherwise' as 'if you don't delete scalar you will get memory corruption'.

                    home

                    C Offline
                    C Offline
                    Code o mat
                    wrote on last edited by
                    #13

                    Guess i should express myself more clearly, sorry... :)

                    > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

                    1 Reply Last reply
                    0
                    • C Code o mat

                      Correct me when i am wrong but -at least in debug- when you allocate an array using new, the system will allocate somewhat more bytes than explicitly needed by your array and will place some special information infront and after your block. When you delete the array the system will check these special values infront and after the array and if it does not find what it expects it will complain about it because this probably means you wrote to memory you should not have written to. True, the example there was a bad one, i should have wrote int_array[5] = 4; instead of int_array[10] = 4;, because 10 is WAY after the lest element of the array...

                      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

                      N Offline
                      N Offline
                      Niklas L
                      wrote on last edited by
                      #14

                      How unbelievable it might seem, there are even more ways to corrupt a piece of memory than there are unspecific questions on this forum :)

                      home

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups