Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Freeing Up Memory

Status
Not open for further replies.

booeyOH

Programmer
May 30, 2007
48
US
Hello,
I have a script that does a lot of different things. In the process it racks up the memory to over 700mb. This is way too much. One thing I would love to do is free up some memory in the middle of the script (maybe after dumping some information to a database or something). The only problem is that I can't seem to find anything about this except for using "unset()", which doesn't seem to do anything about the memory.

Ideas?

Thanks,
BooeyOH
 
if you are finished with DB queries you may use
mysql_free_result($result);
but this would be almost a done deal, you thought about it didn't you

mysql_free_result is only to be used when performing extensive queries thus using a large amount of memory

 
unset() does free up memory by removing the pointers that direct the PHP script engine to the data contained in those variables. If you have large arrays or strings that are no longer needed, you should see some improvement by unset()ing them.

Also, as webdev said, use mysql_free_result() after you are done with the data returned by your queries.
 
hmmmm, I have an object that gets created in loop, and it doesn't free up the memory even when I unset it.

BooeyOH
 
You may want to re-think how the script works. If you're pulling large amounts of data to an array, you could initialize the array when you're done with it.

$arrayname = array();

Another option is to create temporary tables in the database to store that info rather than a large array. That will free up memory and allow you to access the data directly from the database again.

There are many ways to optimize your programs. I seem to find a better way to do something every time I look at an old program of mine.

What does this script do?

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top