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. Freeing the memory using delete operator for a class object created using new operator gives exception

Freeing the memory using delete operator for a class object created using new operator gives exception

Scheduled Pinned Locked Moved C / C++ / MFC
11 Posts 8 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.
  • M Offline
    M Offline
    manoharbalu
    wrote on last edited by
    #1

    Freeing the memory using delete operator for a class object created using new operator gives exception. The class is class CSnp : public CObject { public: CSnp(); ~CSnp(); char liststr[50]; char sSnpDesc[50]; CTime tDateTime; int iDCSSerialKey; }; Is there anything wrong in the class?

    C C H N A 5 Replies Last reply
    0
    • M manoharbalu

      Freeing the memory using delete operator for a class object created using new operator gives exception. The class is class CSnp : public CObject { public: CSnp(); ~CSnp(); char liststr[50]; char sSnpDesc[50]; CTime tDateTime; int iDCSSerialKey; }; Is there anything wrong in the class?

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      class looks fine. make sure you haven't written past the ends of either of those arrays, though.

      image processing toolkits | batch image processing

      1 Reply Last reply
      0
      • M manoharbalu

        Freeing the memory using delete operator for a class object created using new operator gives exception. The class is class CSnp : public CObject { public: CSnp(); ~CSnp(); char liststr[50]; char sSnpDesc[50]; CTime tDateTime; int iDCSSerialKey; }; Is there anything wrong in the class?

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #3

        I don't know, you didn't provide the class implementation code.

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        1 Reply Last reply
        0
        • M manoharbalu

          Freeing the memory using delete operator for a class object created using new operator gives exception. The class is class CSnp : public CObject { public: CSnp(); ~CSnp(); char liststr[50]; char sSnpDesc[50]; CTime tDateTime; int iDCSSerialKey; }; Is there anything wrong in the class?

          H Offline
          H Offline
          Hans Dietrich
          wrote on last edited by
          #4

          This might happen if you continue to use the pointer after using delete. After delete, set the pointer to 0, to make it easier to catch this.

          Best wishes, Hans


          [Hans Dietrich Software]

          1 Reply Last reply
          0
          • M manoharbalu

            Freeing the memory using delete operator for a class object created using new operator gives exception. The class is class CSnp : public CObject { public: CSnp(); ~CSnp(); char liststr[50]; char sSnpDesc[50]; CTime tDateTime; int iDCSSerialKey; }; Is there anything wrong in the class?

            N Offline
            N Offline
            Nemanja Trifunovic
            wrote on last edited by
            #5

            Any reason you are using char arrays instead of something like CString?

            utf8-cpp

            C 1 Reply Last reply
            0
            • N Nemanja Trifunovic

              Any reason you are using char arrays instead of something like CString?

              utf8-cpp

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #6

              Because that is a right (warranted by the constitution) of the native developer?

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              N 1 Reply Last reply
              0
              • C CPallini

                Because that is a right (warranted by the constitution) of the native developer?

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                N Offline
                N Offline
                Nemanja Trifunovic
                wrote on last edited by
                #7

                God forbid I infringe upon anyone's rights ;P However, char sSnpDesc[50]; sounds like some sort of description, and I've seen descriptions longer than 50 chars.

                utf8-cpp

                C 1 Reply Last reply
                0
                • N Nemanja Trifunovic

                  God forbid I infringe upon anyone's rights ;P However, char sSnpDesc[50]; sounds like some sort of description, and I've seen descriptions longer than 50 chars.

                  utf8-cpp

                  C Offline
                  C Offline
                  CPallini
                  wrote on last edited by
                  #8

                  It looks just "A snapshot in the family album". I don't know if Daddy had more than 50 characters. :)

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  S 1 Reply Last reply
                  0
                  • C CPallini

                    It looks just "A snapshot in the family album". I don't know if Daddy had more than 50 characters. :)

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                    [My articles]

                    S Offline
                    S Offline
                    Stefan_Lang
                    wrote on last edited by
                    #9

                    In World of Warcraft the maximum number of characters you can create over all servers is 50, so this definition looks perfectly valid to me! ;P

                    N 1 Reply Last reply
                    0
                    • S Stefan_Lang

                      In World of Warcraft the maximum number of characters you can create over all servers is 50, so this definition looks perfectly valid to me! ;P

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

                      Ah! The trailing null!

                      1 Reply Last reply
                      0
                      • M manoharbalu

                        Freeing the memory using delete operator for a class object created using new operator gives exception. The class is class CSnp : public CObject { public: CSnp(); ~CSnp(); char liststr[50]; char sSnpDesc[50]; CTime tDateTime; int iDCSSerialKey; }; Is there anything wrong in the class?

                        A Offline
                        A Offline
                        Albert Holguin
                        wrote on last edited by
                        #11

                        If you specify the exception, it may provide more information for us to give you feedback. Make sure of a few things: -You're not using the pointer after delete -You're not calling delete on something that has already been deallocated -You're not calling delete on someone else's private member -You're not deallocating across DLL boundries

                        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