1
davidthomas1
PHP question - destroy an object - is it necessary?

Hi there,

When doing OO programming with PHP 4.x , is it necessary to explicitly destroy an object (instance of a class) after it's served it's purpose or is that done automatically?

In other words, do you need to write a line of code to destroy an object once it's been used?

I'm just concerned about freeing up the memory.

thanks,
みんなちがってみんないい。

XOOPS 2.0.13.2

2
Mithrandir
Re: PHP question - destroy an object - is it necessary?

In PHP 4.x there really isn't a sure way to destroy an object and be sure to free the memory. You can unset($object) but that "just" kills the reference...

PHP 5 should be stronger in this, but the need is debatable since everything is freed from memory, when the page is done loading.
"When you can flatten entire cities at a whim, a tendency towards quiet reflection and seeing-things-from-the-other-fellow's-point-of-view is seldom necessary."

Cusix Software

3
davidthomas1
Re: PHP question - destroy an object - is it necessary?

Thanks very much for your reply.

I know is some languages like VB, it's a good idea to destroy an object once it's finished with, for example:

set objMyObject nothing


However, given that the memory is freed once the page is loaded, that seems this is uneccesary with PHP.

thanks again,

D.
みんなちがってみんないい。

XOOPS 2.0.13.2

4
Dave_L
Re: PHP question - destroy an object - is it necessary?
  • 2005/7/5 1:49

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Using unset after you're finished with an object allows PHP to potentially reclaim the memory used by the object immediately, instead of after all references to the object go out of scope or execution completes.. It also ensures that errors will be issued if you have some stray code that tries to use the object.

5
davidthomas1
Re: PHP question - destroy an object - is it necessary?

I see,

thanks for your input.

D.
みんなちがってみんないい。

XOOPS 2.0.13.2

Login

Who's Online

509 user(s) are online (405 user(s) are browsing Support Forums)


Members: 0


Guests: 509


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits