Am 17.07.2011 17:40, schrieb Hannes Landeholm:
If you are writing code that caches objects/relations and that caching has a
significant impact on memory usage, you need to care about memory
allocation/management per definition.
Right. That's what I am talking about...a callback on high-memory consumption and a way to check which objects I could liberate from my cache.

So then you have to learn how OOP
memory managment works (which should be obligatory anyway if you want to
call yourself a OOP-developer IMO).
I do call myself an OOP-developer but maybe I shouldn't, because I've never heard of "OOP Memory Management". Would you care to explain in private?

A common argument to why programmers
should not start with a garbage collected language is that it prevents them
from understanding memory allocation concepts.
The other argument being that if you're not using a gc-language, it might prevent you from starting at all.

It would probably be simple to implement such functionality. However this
would be bad design since it would violate responsibility isolation. PHP
should expose as little internal stuff to the userland as possible - unless
there are a clear use case for it, and even then it might be a bad idea
because it could cause BC breaks in future updates.

I agree with you that it's not an ideal solution. But my solution would not introduce a completely new concept to the language, but would allow advanced PHP-users to write their own custom bred solution. => "give the language a rest"

If you write code that
depend on reference counts or memory usage - you're doing something wrong.
Why?...because it's not discrete? I am only taking advantage of what is already there...

The only scenario I could imagine where you could "free memory"
spontaneously on demand (when the arbitrary OOM limit is reached) - is if
that would be cached data.
Exactly the case I wanted to cover.

Caching is a very complicated subject that is not
directly related to weak references. Start a separate thread about it and
present clear use cases if you have anything special in mind.
I know but WeakReferences (or SoftReferences) would be a solution to this, right? It's not unrelated.

For example, I need weak references to store a table of "back references"
between objects for later reference (depends on how you use the objects). If
A references B i also need a weak reference from B to A so if B should be
replaced with a C object I need the weak reference from B to A to know that
A should be updated to point to C instead (if A still exists). This is not
related to caching.

I am looking forward to the RFCs usecases...this sounds interesting.


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to