locked
delete in windows mobile 6 RRS feed

  • Question

  • hi

    i am new win the mobile area but not in c++

    i am using visual studio 2005 and mobile 6 sdk

    is there a problem with delete?

    is seems that i can delete the same pointer twice, and even delete local variable on the stack

    i am used to see that after delete the data in the variable is changing but not here

    how can i know that i am really deleting?

    i cannot even enter to delete to debug it

    #include "stdafx.h"
    #include <windows.h>
    #include <commctrl.h>


    int _tmain(int argc, _TCHAR* argv[])
    {

        int* i=new int(10);
        delete i;
        delete i;
        return 0;
    }

    thanks
    Thursday, October 23, 2008 9:08 AM

Answers

  • Hi,

     

    There is nothing wrong in deleting a valid pointer twice or event a million times in a row - please check http://www.devx.com/tips/Tip/14443

     

    You can't debug the "delete" Smile

     

    You can also check this article : http://msdn.microsoft.com/en-us/library/kftdy56f(VS.71).aspx

     

     

     

     

    Thursday, October 23, 2008 1:51 PM


  • hi

    have a look on it
    char *a = malloc(128*sizeof(char));
    free(a);
    ... Do stuff
    free(a); // A check for NULL would indicate nothing.
    // This memory space may be reallocated and thus we may be freeing
    // memory we do not intend to free or portions of another block of
    // memory. The size of the block of memory allocated is often held
    // just before the memory block itself..

    i think same the case with C++ delete operator too

    have a look on it

    C Memory Leaks and Memory Corruption

     hope it help you
    -------------------------------
    Chandra Kant Sing

    Friday, October 24, 2008 10:18 AM

All replies

  • Hi,

     

    There is nothing wrong in deleting a valid pointer twice or event a million times in a row - please check http://www.devx.com/tips/Tip/14443

     

    You can't debug the "delete" Smile

     

    You can also check this article : http://msdn.microsoft.com/en-us/library/kftdy56f(VS.71).aspx

     

     

     

     

    Thursday, October 23, 2008 1:51 PM


  • hi

    have a look on it
    char *a = malloc(128*sizeof(char));
    free(a);
    ... Do stuff
    free(a); // A check for NULL would indicate nothing.
    // This memory space may be reallocated and thus we may be freeing
    // memory we do not intend to free or portions of another block of
    // memory. The size of the block of memory allocated is often held
    // just before the memory block itself..

    i think same the case with C++ delete operator too

    have a look on it

    C Memory Leaks and Memory Corruption

     hope it help you
    -------------------------------
    Chandra Kant Sing

    Friday, October 24, 2008 10:18 AM