Jump to content

seeing memory


drifter

Recommended Posts

Is there a way to see what is stored in memory? I am watching my process and CPU stats, and I see that one of my imports that takes several hours starts out fine, but as it goes, it takes up more and more memory until if causes problems.

I have unset everything I use - every loop through I use the same variables. I got rid of all array_push() and thing like that that grow. I unset everything in my functions...

I do use fopen and fgets - as this reads line by line, do this somehow store the previous lines? I am not really sure where all this extra stuff is coming from - this is my only guess.
Link to comment
Share on other sites

If you're using large multi-dimensional arrays in php 4, and particularly if you are using serialize()/unserialize(), there are some memory leaks related to that.

However it's more likely that the leak is due to something not being freed.

Are you using a database interface?  If so, which one and how do you ensure that it frees all space used after each query?  Note that even if you let a postgres resource identifier go out of scope, you will lose memory!  You must call pg_free_result() on them.

If you're dealing with php data (except the case mentioned above), then as long as your variables go out of scope at the end of each function you should have nothing to worry about.  PHP will automatically clean up variables that can't be referenced anymore.  But it will not always automatically clean up after external libraries implmented in C.

To see if you are losing data outside of php's tracking, use memory_get_usage().  If it reports a number vastly lower than the process's real memory usage, you have a leak.  Keep in mind that if you have lots of modules compiled in, then your php processes will start with high virtual size.  This is ok, as most of that is never used.  Watch the difference between the process starting size and how much it increases if it starts out large.
Link to comment
Share on other sites

OK  - I found the problem... not sure the best way to fix it.

The problem is in the pear DB class - On my inserts or updates

[code]
$sql="insert ...."
$db->query($sql);
[/code]
there is no result to clear

if I put mysql_query() in place of the $db->query then the memory does not do up. The question is what can I do? Do I really want to have the mysql_query() statement in the middle of one of my pages when I use the DB class for everything else? Do I really want to mess with the call or upgrade to MDB2? and will that have the same problem?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.