Re: unset and circular references
| From: | Abu Warez | Date: | Fri, 27 Jun 2008 16:00:08 +0000 |
| Subject: | Re: unset and circular references | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-276065@lists.php.net to get a copy of this message | ||
--- On Fri, 6/27/08, Thijs Lensselink <dev@lenss.nl> wrote:
> From: Thijs Lensselink <dev@lenss.nl>
> Subject: Re: [PHP] unset and circular references
> To: php-general@lists.php.net
> Date: Friday, June 27, 2008, 5:21 PM
> Quoting Abu Warez <abuwarez@yahoo.com>:
>
>
> I think this happens because there is still a reference to
the B object.
> According to the manual :
>
> The destructor method will be called as soon as all
> references to a
> particular object are removed or when the object is
> explicitly
> destroyed or in any order in shutdown sequence.
>
> So as long as A has a reference to B the __destructor will
> not be called.
I think you mean: "As long as B has a ref to A (which, indeed, creates B),
the destructor of A will not be called".
I agree with that, but in this case the garbage collector should detect
that the reference to object $a is from an object $m_b which is created (and maintained) again by
the first object $a. In other words, if object $a is not needed then its member $m_b (which has a
reference to $a) is not needed neither. So in this case, in my opinion, if one wants to destory
object $a then the reference from $m_b to $a should not count.
This issue is really frustrating because because in my code I have something like (where $a is of
type class A):
for ( $id ... )
{
$a = daoMyClass->LoadById( $id );
.... modify $a ...
/* persist modified $a */
daoMyClass->Update( $a );
unset( $a );
}
unset, as stated, does not destroy $a and all the loaded $a's remain in
memory until the script ends. Rising the memory limit is not a solution
because the count of $a objects grows between script calls. Any ideas?
Thx,
Abu