Object-oriented – In PHP, should I delete objects immediately after use

classobject-orientedPHPprogramming practices

I've read in PHP Advanced and Object Oriented Programming by Larry Ullman that it is good programming practice to delete object immediately after use but reason is given nowhere.

I am a student web developer and objects in web applications are deleted automatically as soon as the script finishes. So, there seems no good reason to delete them manually.

So, my question is what are the good reasons to delete unnecessary objects after use other that blindly following a convention?

Best Answer

No, you do not need to delete an object after its use in PHP. Let PHP's garbage collection take care of it for you.

There may be some obscure performance reasons to unset an object after you are done with it in very specific situations. But such cases are not everyday events, and they will be clear when you see them.

Related Topic