Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54346 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50506 invoked from network); 4 Aug 2011 10:44:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Aug 2011 10:44:02 -0000 Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.83.42 as permitted sender) X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 74.125.83.42 mail-gw0-f42.google.com Received: from [74.125.83.42] ([74.125.83.42:34636] helo=mail-gw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 94/85-18399-1F77A3E4 for ; Thu, 04 Aug 2011 06:44:01 -0400 Received: by gwb17 with SMTP id 17so1075875gwb.29 for ; Thu, 04 Aug 2011 03:43:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=e9vr2SCvWxVjBhtSGB6hT6HAmzLj9odRwcOFrir3esE=; b=FZZxsv0nGKfA++wuNdoA2HMkxMI8Xz6ZpYvH/KLUUuCwM1CSqc6yUQY/9VOLL8y5HP vRp5n9p7eNVoowYovy25hJh0GAZ5fEg5yItAgtDNKlpVTuJdBZhYXFcpnyvicB49pprQ 36LtIqV/RjzXf448PNDDy5WqZwu1xGBB5WZTY= MIME-Version: 1.0 Received: by 10.236.190.234 with SMTP id e70mr886101yhn.202.1312454638821; Thu, 04 Aug 2011 03:43:58 -0700 (PDT) Received: by 10.147.82.17 with HTTP; Thu, 4 Aug 2011 03:43:58 -0700 (PDT) In-Reply-To: <4E3A71B2.3060302@lsces.co.uk> References: <4E3A71B2.3060302@lsces.co.uk> Date: Thu, 4 Aug 2011 12:43:58 +0200 Message-ID: To: Lester Caine Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Memory management ... From: tyra3l@gmail.com (Ferenc Kovacs) 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 t= he > past I got 'out of memory', now I just say 'some detail not available'. I= f > 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 reco= rd, > and simply build the page via the one object which is sequentially loaded > ... slower, but memory efficient. Never do 'SELECT * FROM', always specif= y > 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 n= ot > 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 j= ust > 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. --=20 Ferenc Kov=C3=A1cs @Tyr43l - http://tyrael.hu