php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46126 memory leak when reassigning object
Submitted: 2008-09-19 15:37 UTC Modified: 2008-10-18 18:09 UTC
From: lorenzo dot reffo at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.6 OS: Linux Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: lorenzo dot reffo at gmail dot com
New email:
PHP Version: OS:

 

 [2008-09-19 15:37 UTC] lorenzo dot reffo at gmail dot com
Description:
------------
I encountered an error while assigning multiple class to an object into another class.

Suppose to have a class A in which is defined a property. At the begin, I use the property as an instance of another class B, then I do an 'unset' of property before creating assigning it an instance of class C.

Reproduce code:
---------------
class B {
    # do something
}

class C {
    # do something
}

class A {
    private $_prop;

    function __construct() {
        $this->_prop = new B();
    }

    function Re () {
        unset($this->_prop);
        $this->_prop = new C();
    }
}

$h = new A()
$h->Re();
unset($h);

Expected result:
----------------
I expect it to work correctly (I read a post before where staff said it has been fixed in version 5.2.x).

Actual result:
--------------
it crashes when calling 'Re' method giving me an error:

Allowed memory size of ... bytes exhausted etc.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-22 06:50 UTC] lorenzo dot reffo at gmail dot com
Thank you Felipe for your quick answer, unfortunately I haven't the rights to use CVS on this server... anyway, in case anyone will encounter the same problem I report a "temporary" solution I found: error is raised only when using the unset function, while it will work correctly simply setting a NULL value for property. So you just have to replace a line such as

if(isset($_propertyname)) unset($_propertyname);

with a line like

$_propertyname = NULL;

I use version 5.2.4-2 of PHP (on ubuntu), hope this post will be useful
 [2008-09-27 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2008-10-18 18:09 UTC] felipe@php.net
.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Nov 26 06:00:02 2025 UTC