PHP Object new method for Class, Memory Leak and Unset Method

落花浮王杯 提交于 2019-12-22 00:28:22

问题


I have Created following class in flie index.class.php :-

<?php
class index{
        public function loadTitle() {
            $title = "Welcome to My Website";
            return $title;
        }
    }
?>

and now, I am using it like below in my index.php file

    <?php
        require_once("index.class.php");
        $obj = new index();
        echo $obj->loadTitle();
    ?>

, now my question is Page will become heavy with lots of article and images, and i will expect 1500-2500 user every day in it.

Do, i need to also unset memory, i know PHP has its own garbage collector, but following URL scares me out :- www.google.com/search?q=php+memory+leak+with+new

and i saw few question in stackoverflow that it does consumes memory, and certain people have suggested to use unset function, but i am not sure, how to do it..

This is my try.. :-

Do i need to only call

<?php
    unset($obj); // At the end of the page, or where i will no more be using this object.
?>

or i have to set NULL value too.

<?php
    $obj = NULL;
    unset($obj);
?>

is above code fine for releasing memory, or do i need to do something else too.. Please suggest and teach me. It will be very helpful.

Thanks

来源:https://stackoverflow.com/questions/18558805/php-object-new-method-for-class-memory-leak-and-unset-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!