Hello,
I have written an XML parser in php using xml_parser_create() and xml_set_element_handler(). The xml file parsed is around 73MB. My problem is, even after the XML file is parsed, the results obtained and the browser closed, it's still taking up about 30% of memory (by typing ps -aux at the command line). How do I get it to free up the memory after execution?
Please, any help would be great!
Thank you in advance.
Nivi.
Xml parser - how to free memory space??
Moderator: General Moderators
-
nivritha_g
- Forum Newbie
- Posts: 3
- Joined: Wed Jul 12, 2006 5:41 pm
hmm... xml_parse_free() and unset() perhaps.
-
nivritha_g
- Forum Newbie
- Posts: 3
- Joined: Wed Jul 12, 2006 5:41 pm
xml_parser_free and ob_end_clean don't seem to work
I have tried xml_parser_free() as well as ob_end_clean().
But none of them seem to work.
By unset(), u mean unset every variable I have used individually?
Any suggestions?
Thank you.
Nivi.
But none of them seem to work.
By unset(), u mean unset every variable I have used individually?
Any suggestions?
Thank you.
Nivi.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Re: Xml parser - how to free memory space??
It is likely that what you think you see, isn't what you really see.nivritha_g wrote:My problem is, even after the XML file is parsed, the results obtained and the browser closed, it's still taking up about 30% of memory (by typing ps -aux at the command line). How do I get it to free up the memory after execution?
In Linux (and other Unix variants), ps shows the amount of memory used by a process. However, the memory used can (and in the case of Apache, does) include caches.
In a nutshell, it is more expensive for a process to release memory, and request it again (often), so they have a tendency to be 'laggy' in releasing the memory. After they *clear* the variables from memory, they will keep a large amount of the allocated memory as allocated free space for it to use. Most people see it as "memory not being freed", when in fact, it is the application/daemon trying to provide a better, more responsive performance.
There are of course ways around that. If I recall correctly, reloading the config (NOT restarting the server) triggers Apache's release/cleanup cycle, so that should serve your purpose.
Of course, if it is PHP itself (running as a CGI, for example), then I'm stumped on how to get PHP to release it more quickly (short of the unset() mentioned earlier)
-
nivritha_g
- Forum Newbie
- Posts: 3
- Joined: Wed Jul 12, 2006 5:41 pm
Resolved!!!!
Hello,
I finally understood what the problem was.
I was reading the whole xml file into an array using file() command (though i needed just about first 100 lines). Unsetting the array didn't make any difference.
But if I read just the lines I need using fgets(), the memory usage problem just disappeared.
Thank you all for your advice.
Nivi.
I finally understood what the problem was.
I was reading the whole xml file into an array using file() command (though i needed just about first 100 lines). Unsetting the array didn't make any difference.
But if I read just the lines I need using fgets(), the memory usage problem just disappeared.
Thank you all for your advice.
Nivi.