RE: [PHP-DEV] [VOTE] Weak References
| From: | Jonathan Bond-Caron | Date: | Wed, 03 Aug 2011 22:35:08 +0000 |
| Subject: | RE: [PHP-DEV] [VOTE] Weak References | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-54328@lists.php.net to get a copy of this message | ||
On Wed Aug 3 05:16 PM, Lester Caine wrote:
> Jan Dolecek wrote:
> > I was waiting for this for a while! I wrote a blog post how to get
> > best benefits from weak references:
> > http://blog.juzna.cz/2011/08/weak-references-in-php/
> > Perhaps this will help showing people what are they good for.
>
Or you can use various caching algorithms (LRU, MRU, ..) to reduce memory usage:
$this->cache = new ArrayLimit(2);
$this->cache->add(new LargeObject('A'));
$this->cache->add(new LargeObject('B'));
$this->cache->add(new LargeObject('C'));
$this->cache->count(); // 2
To solve a "caching problem" weak references aren't very helpful since there's
no way to know when or which objects will be garbage collected (non-deterministic).