Re: Re: Freeing memory for DOMDocument

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Nathan Rixham wrote:
Jesús Enrique Muñoz Fernández wrote:
Maybe you could find and answer here:

*http://drupal.org/node/81037

Some people have the same problem, i was this trouble in the past and i fix it increasing the *memory_limit *in php.ini file*

Anyway read the posts in the url that i wrote.



> To: php-general@xxxxxxxxxxxxx; jcboget@xxxxxxxxx
> Date: Wed, 7 Jan 2009 15:21:50 +0000
> From: nrixham@xxxxxxxxx
> CC: php-general@xxxxxxxxxxxxx
> Subject:  Re: Freeing memory for DOMDocument
>
> Christoph Boget wrote:
> > I'm running through a large dataset and am generating/manipulating XML
> > documents for each record. What's happening is that after a while, I
> > get a fatal error saying:
> >
> > Fatal error: Allowed memory size of 167772160 bytes exhausted (tried
> > to allocate 32650313 bytes)
> >
> > Each XML file I generate (an manipulate) can range from just a few
> > megs to upwards of 35 megs. Judging from the error above, it looks
> > like the memory for the DOMDocument objects I instantiate is not
> > getting freed; it just continues to stay in memory until the memory is
> > completely exhausted. The method (in my object) I am using to
> > instantiate a new DOMDocument is as follows:
> >
> > protected function createCleanDomDocument()
> > {
> > /*
> > if(( isset( $this->oDomXPath )) && ( !is_null( $this->oDomXPath )))
> > {
> > unset( $this->oDomXPath );
> > }
> >
> > if(( isset( $this->oDomDocument )) && ( !is_null( $this->oDomDocument )))
> > {
> > unset( $this->oDomDocument );
> > }
> > */
> > $this->oDomDocument = new DOMDocument( '1.0', 'iso-8859-1' );
> > $this->oDomXPath = new DOMXpath( $this->oDomDocument );
> > }
> >
> > which is used in both the constructor of my object and in a few other
> > places. I would think that when the new DOMDocument is instantiated,
> > the memory used for the old value would get freed. As you can see,
> > I've even tried to unset the variables but that doesn't seem to help
> > matters much, either.
> >
> > Does anyone know how (or even if) I can explicitly free the memory
> > used for the DOMDocument? Any help/advice would be greatly
> > appreciated!
> >
> > thnx,
> > Christoph
>
> I've had exactly the same problem and couldn't find a way around it;
> even after unsetting every variable in my scripts inside a for/while
> loop; in the end I opted for a CLI script which opened worker threads
> then killed/restarted them when memory usage was X.
>
Just because.. I'm going to write out my thoughts on this and see if we can come to any kind of fixed bug or solution.

The issue is that memory assigned to DOMDocuments is not being freed correctly.

The job of freeing memory falls to the garbage collection; which implements the following algorithm: http://www.research.ibm.com/people/d/dfb/papers/Bacon03Pure.pdf

(root buffer size of 10000)

AFAIK a variable becomes a candidate for gc when it is no longer required (unset and no references to it?)

because of the way we use domdocument often we have many variables referencing existing or created nodes within the document; as well as xpath and suchlike; thus it stands to reason that unless all of these are also unset the DOMDocument will not be caught by gc.

first test then is to check that all variables that even sniff at the DOMDocument (or nodes within) are unset.

technically I'd guess that a script that loads an xml document in to a DOMDocument, then unsets it on a for loop should never grow the used memory. I'm going to write a little test script to prove this in a mo.


Memory is freed correctly with DOM objects. While a DOMDocument object is destroyed once there are no more references to it, the underlying XML document structure is only destroyed once all DOMNode objects that are members of the document are destroyed as well.

Rob

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux