Re: [Dev-C++] deleting an array properly?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Alfred P. R. <al...@ya...> - 2005-09-28 17:51:51
|
Hi Dane, Provided that you allocated the variable in the form of, lets say: double **variable; variable = new double[256]; then the correct way to delete would be: delete [] variable; However if you used malloc, delete will not work. Try not to use malloc and free if possible in C++ code. If you did use malloc, delete is not the proper keyword, free would be the proper keyword. See http://www.cppreference.com/. Dane Ensign <da...@de...> wrote: Hi, Thank you in advance for any help you can offer. I am trying to delete an array of pointer to objects and its throwing an error, which I cant figure out how to solve. The message is: --Emp_app_C(1024) malloc: *** Deallocation of a pointer not malloced: 0xbffff9f4; This could be a double free(), or free() called with the middle of an allocated block; Try setting environment variable ------MallocHelp to see tools to help debug First I build my array of pointers to objects: --employee* empList[MAX_EMPLOYEES]; After populating the array, I tried to delete it using these 2 different statements: 1. delete[] empList; 2. delete empList; Please can someone show me the correct statement that would delete this array properly? Best regards, Dane Ensign Alfred P. Reaud |