Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple problem with memo allocation

Status
Not open for further replies.

ebuBekir

Technical User
Sep 6, 2001
22
0
0
DE
Hi @ all!

I have problems deallocating space.

MfContour2D* profile = new MfContour2D [20];


When I try to deallocate space, I get an ‘error’(Debug Assertion Failed!) und das Programm wird abgebrochen.
if ( profile != NULL )
delete profile;

The following does not work, either.
if ( profile != NULL )
delete profile;

Does anybody have an idea, what the problem may be?
Thanks a lot,…
:cool:
 
Have you tried


if(profile)
delete[] profile;


?

If it does not work, the pointer was maybe modified after allocating memory. Or the memory was already deleted but the pointer was not set to NULL.


 
Sorry, I already did that. There is a mistake in my text above.
>
> if ( profile != NULL )
:> delete [] profile;
>
>The following does not work, either.
> if ( profile != NULL )
> delete profile;
:cool:
 
What kind of assertion do you get (file name, line nr)?
 
If you misused the profile array in your program it will throw this exception. Look for a situation where you might have gone over the size of the array (20).

I get this error when I make the following type of mistake:

const int Rows = 25;
const int Cols = 20;

myStruct *profile = new myStruct[20];

for (i = 0; i < Rows; i++) // Rows = 25
profile.m_data = &quot;some data&quot;; // profile holds 20

Here I inadvertently used Rows instead of Cols, so I wrote beyone the allocated memory of profile. The program might or might not run, but it will surely throw an exception when you attempt to free the profile object.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top