[Xapian-devel] PHP Latest
Sam Liddicott
sam at liddicott.com
Thu Apr 20 17:22:15 BST 2006
Olly Betts wrote:
>On Thu, Apr 20, 2006 at 05:11:14PM +0200, Daniel M?nard wrote:
>
>
>>BTW, you remember me a problem I had with my wrapper and that I have not
>>investigated : I had to explicitely release the object (php should do it
>>automatically). For example, with a WritableDatabase, the lock file was not
>>removed if I didn't write "$db=null".
>>
>>
>
>For the wrapper class, or for the resource thing that you pass to the
>flat API?
>
>I believe SWIG sets a destructor to run on the resource, but I guess PHP
>doesn't call it (I notice simpleindex.php explicitly sets the database
>to Null).
>
>
>
>>I will have to test the new wrapper to check that we don't have a similar
>>problem.
>>
>>
>
>If it doesn't, we can easily generate a destructor to explicitly set the
>swig_ptr to Null. Assuming PHP always runs object destructors which
>I'd really hope it does...
>
>
Aye this is a sticky area. php till php5 actually hasn't had any proper
object destructors.
PHP carefully tracks memory allocations to free them, and it ref-counts
and we get our destructor called then (which is why setting to null
works), but it looks like on page shutdown time the memory is free'd but
the destructors are not called. Shame on php.
This of course means that there will be memory leaks too (under apache)
Looks like swig-php needs a hash or collection of allocated objects so
it can free them on php shutdown;
I don't now if this is true now but it will be when swig handles
callbacks a bit better, wrapped objects might have references to php
objects which have references to wrapped objects.... indeed.
PHP - before proper php destructors - has had register_shutdown_function
(or something with a similar name) where code could be specified to
clean up resources on php shutdown.
We should perhaps look and see how mysql handles closing non persistent
connections on shutdown and get tips from there, but could at least
perhaps do some register_shutdown_function when wrapped objects are
returned, perhaps by keeping a private hash of object references and
iterating over those afterwards.
Private php hashes are done with static vars:
class whatever {
function &private_hash() {
static $hash;
if (! isset($hash)) $hash=array();
return $hash;
}
}
$hash=&whatever::private_hash();
that type of stuff - but it would keep an extra ref, of course, so
$db=NULL would not work....
it's hell!
I recall that MSIE has memory leaks related to javascript objects
referencing dom stuff which itself references javascript stuff.
Sam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.tartarus.org/pipermail/xapian-devel/attachments/20060420/ebcc50c9/attachment.htm
More information about the Xapian-devel
mailing list