Access in freed memory

From Appmethod Topics
Jump to: navigation, search

Go Up to Access Errors

An Access In Freed Memory error occurs when memory is accessed after it has been freed. Typically, the memory has been allocated with new or malloc and deallocated with delete or free. The following code shows an example:

class someclass{
    int fnumber;
    int getnumber(){return fnumber;}
    void setnumber(int nw){fnumber = nw;}
    int doublev(int val){return val*2;}
    int publicalval;


void myf()
  someclass *myc = new someclass();
  delete myc;
  myc->publicalval = 10; // error

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

  return 0;