FAQ
I'm still trying to get my head around this 'Weak Reference' thing, but since
I'm still working to be compatible with PHP5.2 then I've not taken much notice
of this 'garbage collection' stuff. So this may be where I am missing something?
I manage what material I need using a list of numbers, and create objects as and
when they are required, pulling the detail from the database. There is a limit
on the amount of memory available, so in the past I got 'out of memory', now I
just say 'some detail not available'. If I'm out of space, then I reuse an
existing object that is 'invalid', but to simplify things then much of the time
I don't ACTUALLY need the full record, and simply build the page via the one
object which is sequentially loaded ... slower, but memory efficient. Never do
'SELECT * FROM', always specify just the fields you need at that time.

So it looks like the question I should be asking is "How do you 'drop' an
object?" I think my take on this 'Weak Reference' stuff is that it does not
actually 'create' the object? But I am creating the object because I need to use
it, not because I may need it later? I'll get the database server to do any
heavy processing ... and that may well be a different machine ... I just want
the results. So I try to avoid pulling unnecessary data into the PHP side - I
can only put so much on a client page.

--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

Search Discussions

  • Ferenc Kovacs at Aug 4, 2011 at 10:44 am

    On Thu, Aug 4, 2011 at 12:17 PM, Lester Caine wrote:
    I'm still trying to get my head around this 'Weak Reference' thing, but
    since I'm still working to be compatible with PHP5.2 then I've not taken
    much notice of this 'garbage collection' stuff. So this may be where I am
    missing something? I manage what material I need using a list of numbers,
    and create objects as and when they are required, pulling the detail from
    the database. There is a limit on the amount of memory available, so in the
    past I got 'out of memory', now I just say 'some detail not available'. If
    I'm out of space, then I reuse an existing object that is 'invalid', but to
    simplify things then much of the time I don't ACTUALLY need the full record,
    and simply build the page via the one object which is sequentially loaded
    ... slower, but memory efficient. Never do 'SELECT * FROM', always specify
    just the fields you need at that time.

    So it looks like the question I should be asking is "How do you 'drop' an
    object?" I think my take on this 'Weak Reference' stuff is that it does not
    actually 'create' the object? But I am creating the object because I need to
    use it, not because I may need it later? I'll get the database server to do
    any heavy processing ... and that may well be a different machine ... I just
    want the results. So I try to avoid pulling unnecessary data into the PHP
    side - I can only put so much on a client page.
    if you unset a variable, the zval's refcount for that variable will be
    decreased by one.
    if the refcount reach zero, the zval will be freed.
    http://www.php.net/manual/en/features.gc.refcounting-basics.php

    this was also before 5.3
    the new feature in 5.3 however you can fix the memory leaks that
    happened because of the circular references:
    http://www.php.net/manual/en/features.gc.collecting-cycles.php

    a simple example for circular reference is basically when you have two
    zval, they both reference each other, so their refcount is one, so
    they cannot be freed, but they should been.
    this was addressed in 5.3, now the gc collector will traverse the
    zvals and find such "islands" and free them.

    so to address your question: if you unset your variables you can
    reclaim memory, but there could be edge cases, when you will memory
    leak before version 5.3.

    --
    Ferenc Kovács
    @Tyr43l - http://tyrael.hu
  • Lester Caine at Aug 4, 2011 at 11:36 am

    Ferenc Kovacs wrote:
    so to address your question: if you unset your variables you can
    reclaim memory, but there could be edge cases, when you will memory
    leak before version 5.3.
    So it looks like I'm not hitting any edge cases in the earlier code as some
    sites have been running for years without a reboot ... Must think about doing
    that sometime, running a windows server for 21 months without a reboot might be
    pushing luck :)

    --
    Lester Caine - G8HFL
    -----------------------------
    Contact - http://lsces.co.uk/wiki/?page=contact
    L.S.Caine Electronic Services - http://lsces.co.uk
    EnquirySolve - http://enquirysolve.com/
    Model Engineers Digital Workshop - http://medw.co.uk//
    Firebird - http://www.firebirdsql.org/index.php
  • Johannes Schlüter at Aug 4, 2011 at 1:21 pm

    On Thu, 2011-08-04 at 12:36 +0100, Lester Caine wrote:
    Ferenc Kovacs wrote:
    so to address your question: if you unset your variables you can
    reclaim memory, but there could be edge cases, when you will memory
    leak before version 5.3.
    So it looks like I'm not hitting any edge cases in the earlier code as some
    sites have been running for years without a reboot ... Must think about doing
    that sometime, running a windows server for 21 months without a reboot might be
    pushing luck :)
    PHP frees memory forcefully on request end as good as it can (which is
    quite good) but sometimes a request takes a lot of memory and some
    people try to reduce that.

    johannes
    --
    Lester Caine - G8HFL
    -----------------------------
    Contact - http://lsces.co.uk/wiki/?page=contact
    L.S.Caine Electronic Services - http://lsces.co.uk
    EnquirySolve - http://enquirysolve.com/
    Model Engineers Digital Workshop - http://medw.co.uk//
    Firebird - http://www.firebirdsql.org/index.php

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedAug 4, '11 at 10:17a
activeAug 4, '11 at 1:21p
posts4
users3
websitephp.net

People

Translate

site design / logo © 2022 Grokbase