重新分配一个数组释放由它使用的内存? [英] Reassigning an array frees the memory used by it?

查看:135
本文介绍了重新分配一个数组释放由它使用的内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我班有一个成员变量数组,物品。我会定期重新分配数组是另一种价值,临时数组,像这样的:

My class has a member variable array, items. Periodically I reassign the array to be the value of another, temporary array, like this:

$temp = array();
$temp[] = new Object();
$temp[] = new Object();
$temp[] = new Object();
... etc.

$this->items = $temp;

所以,我可以有内存泄漏?截至这 - $>温度值重新分配给新的价值,$温度,将所有项目(项目都是对象)最初在$这个 - >温度仍萦绕周围,或者他们会被释放?

So, could I have a memory leak? By reassigning the value of $this->temp to a new value, $temp, would all the items (the items are objects) originally in $this->temp still linger around, or would they be freed?

推荐答案

这不会导致内存泄漏。 $ TEMP和$这个 - >项目是同一个数组只是引用。由于PHP是一种垃圾回收的语言,阵列将被删除(垃圾回收)当有到阵列的更多引用。

This will not cause a memory leak. $temp and $this->items are just references to the same array. Since PHP is a garbage collected language, the array will be deleted (garbage collected) when there are no more references to the array.

这篇关于重新分配一个数组释放由它使用的内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆