re: limiting factor I don't completely disagree but then again, in
most cases, it's possible to design the app in a way which resolves
the problem.
Well, this is true, but then it would either:
a) reduce the functionality of the object layer (by eliminating
references to "parent")
b) add unreasonable burden onto the client of the objects to
"undo" the circular reference (having the client essentially
"nullify" one half of the circular reference when done with the
object -- I have used this method in the past to "hack" out the
memory leak, but it's problematic because, well, you have to remember
to do it!)
The situation I am working with presently when using the excellent
Propel (http://propel.phpdb.org) ORM solution, which is able to
represent arbitrary DB structure (which are translated into Object
Graphs) in PHP. Therefore, the idea of "designing around the problem"
isn't really an option because it manages referential integrity of
the objects and thus requires parent<->child "pointers".
As to weak references, you could do weak references in PHP just by
using the indirect property access. Might not be perfect but it's
quite doable.
Awesome! Could you tell me what "indirect property access" is? I
googled for it but there's nothing...
Thanks,
Alan
Andi
At 09:21 PM 12/8/2005, Alan Pinstein wrote:
Generally speaking, if you create a circular reference (whether by
reference or by value), then you will have a "memory leak" until
the end of the request. This is not only true for objects (and
circular references might be indirect) but also for arrays.
sure, of course...
This is a side-effect of reference counting systems, but within the
way PHP is used within a request/response paradigm, it shouldn't be
a real limiting factor in real-life usage.
Well I'd say that using a PHP-CLI script to import bulk data is a
real-life usage and this is definitely a limiting factor. Do you
disagree?
On the contrary, for these kind of apps, garbage collecting systems
have potential to be significantly slower.
Well, Cocoa solves the problem in a manner I consider quite graceful.
In 99% of situations, you don't touch memory management and things
work themselves out like in PHP. However, there is a concept of a
WEAK REFERENCE (a non-ref-counted ptr to the object) that is used
*specifically* in these cases to prevent circular references.
With this type of system, there is no additional overhead because the
GC doesn't have to "detect" circular references and determine if the
objects are orphaned but deadlocked... instead this is a situation
left to the developer to manage.
Now I understand that PHP isn't Obj-C and it's a higher-level
language and that's fine.
However, my question, which still remains unanswered, is that I've
found a way that "seems" to create a weak reference and I'm simply
asking if what I am doing is condoned or just lucky (and thus a bad
idea that will probably break in the future)...
And, if it's just lucky, then what is the solution to the problem? Am
I just SOL? Is the answer simply that if you *need* to create
circular references in PHP, then you *must* accept memory leakage?
Alan
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php