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. dlete pointer.

dlete pointer.

Scheduled Pinned Locked Moved C / C++ / MFC
question
23 Posts 7 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.
  • S Offline
    S Offline
    see me
    wrote on last edited by
    #1

    When ever i try to delete a pointer exception is occuring. if any reson for this?????:confused: yours faithfully ajeeshcv

    T V J H 4 Replies Last reply
    0
    • S see me

      When ever i try to delete a pointer exception is occuring. if any reson for this?????:confused: yours faithfully ajeeshcv

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      how do you do it ? isn't the pointer already deleted (it's a possibility) ?


      TOXCCT >>> GEII power

      [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

      S 1 Reply Last reply
      0
      • T toxcct

        how do you do it ? isn't the pointer already deleted (it's a possibility) ?


        TOXCCT >>> GEII power

        [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

        S Offline
        S Offline
        see me
        wrote on last edited by
        #3

        no...i tried to delete it after checking.:(( if( pPointer ) { delete pPointer; pPointer = 0; } yours faithfully ajeeshcv

        T C 2 Replies Last reply
        0
        • S see me

          When ever i try to delete a pointer exception is occuring. if any reson for this?????:confused: yours faithfully ajeeshcv

          V Offline
          V Offline
          Viorel
          wrote on last edited by
          #4

          Possible causes:

          • un-initialized pointer, like int * p; delete p;
          • pointer does not point to an object created with new: int x; int * p = &x; delete p;
          • multiple execution of delete: int * p = new int; delete p; delete p;
          • pointed zone was altered by other code: int * p = new int; memset(p-100, 0, 1000); delete p;
            Note that null value of pointer does not generate exception. This is OK: int * p = NULL; delete p; -- modified at 3:58 Wednesday 14th June, 2006
          S 1 Reply Last reply
          0
          • S see me

            When ever i try to delete a pointer exception is occuring. if any reson for this?????:confused: yours faithfully ajeeshcv

            J Offline
            J Offline
            John R Shaw
            wrote on last edited by
            #5

            You need to be more specific, what do you mean by delete a pointer? I assume memory pointer, but these days it is hard to say. What compiler of language are you using? INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra

            1 Reply Last reply
            0
            • S see me

              no...i tried to delete it after checking.:(( if( pPointer ) { delete pPointer; pPointer = 0; } yours faithfully ajeeshcv

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              and what is the error ?????


              TOXCCT >>> GEII power

              [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

              S 1 Reply Last reply
              0
              • S see me

                no...i tried to delete it after checking.:(( if( pPointer ) { delete pPointer; pPointer = 0; } yours faithfully ajeeshcv

                C Offline
                C Offline
                Cedric Moonen
                wrote on last edited by
                #7

                What is the exact error ? Maybe your pointer points to an invalid address. You probably left it uninitialized and then try to delete it.


                Cédric Moonen Software developer
                Charting control

                1 Reply Last reply
                0
                • V Viorel

                  Possible causes:

                  • un-initialized pointer, like int * p; delete p;
                  • pointer does not point to an object created with new: int x; int * p = &x; delete p;
                  • multiple execution of delete: int * p = new int; delete p; delete p;
                  • pointed zone was altered by other code: int * p = new int; memset(p-100, 0, 1000); delete p;
                    Note that null value of pointer does not generate exception. This is OK: int * p = NULL; delete p; -- modified at 3:58 Wednesday 14th June, 2006
                  S Offline
                  S Offline
                  see me
                  wrote on last edited by
                  #8

                  In my case the above mentioned 4 cases will not be satisfied. Actual reason is any other.:-> And also as per ur comments int * p = NULL; delete p; how the datas will be deleted from the location which is pointed by p initialy. since u r saying to delete the pointer after asigning the pointer to null.:confused: yours faithfully ajeeshcv

                  T C V 3 Replies Last reply
                  0
                  • T toxcct

                    and what is the error ?????


                    TOXCCT >>> GEII power

                    [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

                    S Offline
                    S Offline
                    see me
                    wrote on last edited by
                    #9

                    exception is occuring. yours faithfully ajeeshcv

                    C T 2 Replies Last reply
                    0
                    • S see me

                      exception is occuring. yours faithfully ajeeshcv

                      T Offline
                      T Offline
                      toxcct
                      wrote on last edited by
                      #10

                      Ajeesh c v wrote:

                      exception is occuring.

                      DAMNNNNN !!! WHICHHHH ????? if you don't provide some descriptions of your error case, how can one help you ?? :~ :mad:


                      TOXCCT >>> GEII power

                      [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

                      S 1 Reply Last reply
                      0
                      • S see me

                        When ever i try to delete a pointer exception is occuring. if any reson for this?????:confused: yours faithfully ajeeshcv

                        H Offline
                        H Offline
                        Hamid Taebi
                        wrote on last edited by
                        #11

                        Can you show how to use pointer and how to declare pointer_**


                        **_

                        whitesky


                        S 1 Reply Last reply
                        0
                        • S see me

                          exception is occuring. yours faithfully ajeeshcv

                          C Offline
                          C Offline
                          Cedric Moonen
                          wrote on last edited by
                          #12

                          That's a very clear description of the problem :~ The solution is: you did something wrong.


                          Cédric Moonen Software developer
                          Charting control

                          S 1 Reply Last reply
                          0
                          • S see me

                            In my case the above mentioned 4 cases will not be satisfied. Actual reason is any other.:-> And also as per ur comments int * p = NULL; delete p; how the datas will be deleted from the location which is pointed by p initialy. since u r saying to delete the pointer after asigning the pointer to null.:confused: yours faithfully ajeeshcv

                            T Offline
                            T Offline
                            toxcct
                            wrote on last edited by
                            #13

                            Ajeesh c v wrote:

                            int * p = NULL; delete p; how the datas will be deleted from the location which is pointed by p initialy. since u r saying to delete the pointer after asigning the pointer to null.

                            he doesn't say it is the things to do... the cases enumerated are possible causes for a crash when deleting a pointer X|


                            TOXCCT >>> GEII power

                            [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

                            1 Reply Last reply
                            0
                            • S see me

                              In my case the above mentioned 4 cases will not be satisfied. Actual reason is any other.:-> And also as per ur comments int * p = NULL; delete p; how the datas will be deleted from the location which is pointed by p initialy. since u r saying to delete the pointer after asigning the pointer to null.:confused: yours faithfully ajeeshcv

                              C Offline
                              C Offline
                              Cedric Moonen
                              wrote on last edited by
                              #14

                              Ajeesh c v wrote:

                              how the datas will be deleted from the location which is pointed by p initialy. since u r saying to delete the pointer after asigning the pointer to null.

                              That's probably your problem. When you do this:

                              int* pTest;
                              if (pTest)
                              delete pTest;

                              You will have an excpetion because you try to delete memory that is unitianalized (you can only delete memory that has been allocated with new). So, to be sure not to delete this 'unexistant' memory, assign NULL to the pointer. This is safe.


                              Cédric Moonen Software developer
                              Charting control

                              1 Reply Last reply
                              0
                              • S see me

                                In my case the above mentioned 4 cases will not be satisfied. Actual reason is any other.:-> And also as per ur comments int * p = NULL; delete p; how the datas will be deleted from the location which is pointed by p initialy. since u r saying to delete the pointer after asigning the pointer to null.:confused: yours faithfully ajeeshcv

                                V Offline
                                V Offline
                                Viorel
                                wrote on last edited by
                                #15

                                According to documentation (http://msdn2.microsoft.com/en-us/library/h6227113.aspx[^]), “You can [...] use delete on a pointer with the value 0”. Therefore instead of

                                if( p != NULL )
                                {
                                    delete p;
                                    p = NULL;
                                }
                                

                                you can use

                                delete p;
                                p = NULL;
                                

                                However, this does not belong to original topic. I think you should put a breakpoint at the line where your block of memory is allocated and the pointer is assigned. Then investigate the pointer’s value and the content of the memory block. Then stop on the line where the pointer is deleted. Check if the pointer contains right address value. Try to use step-be-step execution during deletion. Perhaps the pointer points to an object having destructor, and the problem is within this function.

                                1 Reply Last reply
                                0
                                • T toxcct

                                  Ajeesh c v wrote:

                                  exception is occuring.

                                  DAMNNNNN !!! WHICHHHH ????? if you don't provide some descriptions of your error case, how can one help you ?? :~ :mad:


                                  TOXCCT >>> GEII power

                                  [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

                                  S Offline
                                  S Offline
                                  see me
                                  wrote on last edited by
                                  #16

                                  ok... I think the problem is occuring due to this reason. am initializing the pointer from thread...adn try to delete it from another thread.. if there is any chance of occuring exception???? Please help me... yours faithfully ajeeshcv

                                  T V J 3 Replies Last reply
                                  0
                                  • S see me

                                    ok... I think the problem is occuring due to this reason. am initializing the pointer from thread...adn try to delete it from another thread.. if there is any chance of occuring exception???? Please help me... yours faithfully ajeeshcv

                                    T Offline
                                    T Offline
                                    toxcct
                                    wrote on last edited by
                                    #17

                                    as far as you don't answer my questions, i don't help you furthermore. :zzz:


                                    TOXCCT >>> GEII power

                                    [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

                                    1 Reply Last reply
                                    0
                                    • C Cedric Moonen

                                      That's a very clear description of the problem :~ The solution is: you did something wrong.


                                      Cédric Moonen Software developer
                                      Charting control

                                      S Offline
                                      S Offline
                                      see me
                                      wrote on last edited by
                                      #18

                                      Thats a very precious information for me. Thank you.. yours faithfully ajeeshcv

                                      1 Reply Last reply
                                      0
                                      • S see me

                                        ok... I think the problem is occuring due to this reason. am initializing the pointer from thread...adn try to delete it from another thread.. if there is any chance of occuring exception???? Please help me... yours faithfully ajeeshcv

                                        V Offline
                                        V Offline
                                        Viorel
                                        wrote on last edited by
                                        #19

                                        I think this causes problems if your project’s configuration does not allow multi-threading. You should open the project’s properties dialog and be sure that the C/C++ --> Code Generation --> Runtime Library option contains a right value related to multi-threading. Then rebuild the application.

                                        S 1 Reply Last reply
                                        0
                                        • H Hamid Taebi

                                          Can you show how to use pointer and how to declare pointer_**


                                          **_

                                          whitesky


                                          S Offline
                                          S Offline
                                          see me
                                          wrote on last edited by
                                          #20

                                          The pointer is of a dialog. Initialization: CMyDialog* pMyDialog; pMyDialog = new CMyDialog; pMyDialog->EndDialog(0); if(pMyDialog) { delete pMyDialog; pMyDialog = 0; } yours faithfully ajeeshcv

                                          H 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