Link to home
Start Free TrialLog in
Avatar of heaveneye
heaveneye

asked on

Appropriate way to delete this pointer

It happened that I need to manage some other people's source code. In the source, I found that a pointer it was instantiated as below was not freed after being used:

TCHAR** val= NULL;
val = new TCHAR*[MAX_NB];

However, I am unsure the appropriate way to free up the pointer. I am wondering the followings:

delete val[]; // <----- is this appropriate? or should it be "delete val[][]" ?
val=NULL;

I am quite young on c++ programing, and need some advice from experts.
Avatar of beroetz
beroetz

You should use:

free(val);

This will free the memory and set tour pointer to NULL.
ASKER CERTIFIED SOLUTION
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of heaveneye

ASKER

Thanks