Home > Back-end >  Free (p) we to prevent wild p=NUll pointer. After the program p will automatically release don'
Free (p) we to prevent wild p=NUll pointer. After the program p will automatically release don'

Time:09-30

CodePudding user response:

Finally here no, p will be destroyed, immediately outside the main function can't access the p

CodePudding user response:

If I add commented that a can

CodePudding user response:

Can be added, and, in many of the functions, I observed, after release, variable variable is not set to NULL, that is to say after the release of the if (NULL==p) and must be set up, if you want to reuse the variable and pass NULL judgments can be a problem

CodePudding user response:

After the release of the if (NULL==p) does not have to set up

CodePudding user response:

File pointer in the procedure of our company are used once, after use will not free, until the end of the program, total feel very strange, destroyed the habit,

CodePudding user response:

In a statement after the release of the first line of code is added, no problem for certain, without words, in some cases may have a problem

CodePudding user response:

The original poster described not clear, I detailed said:
Free (p);
, then p=NULL;

Is to use p to behind the pointer can be judged whether has released!
You this example, p finally have no, so there's no need to assign it again!

For a pointer, as long as you will know how to use it, then with a null value is not a must!

CodePudding user response:

Release should connect address didn't also should need not

CodePudding user response:

Delphi seem to have a freeAndNil similar,,, have no in c + + builder?
  • Related