Connecting Tech Pros Worldwide Forums | Help | Site Map

Freeing memory when using Databases

code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,083
#1: 4 Weeks Ago
Does mssql_close() implictly call mssql_free_result()?

I am having memory overflow problems (temporarily set to 72mb)
when including three other scripts from one that all query a mssql database.

All three will run on their own without problem so I am looking at trying to free memory within each script.
They are all 'includes' so the garbage collector does not come into play until the main script ends.

Each scripts connects and disconnects from the DB.
Does mssql_free_result() need to be called as well?

Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,953
#2: 4 Weeks Ago

re: Freeing memory when using Databases


Quote:

Originally Posted by code green View Post

Does mssql_close() implictly call mssql_free_result()?

I am having memory overflow problems (temporarily set to 72mb)
when including three other scripts from one that all query a mssql database.

All three will run on their own without problem so I am looking at trying to free memory within each script.
They are all 'includes' so the garbage collector does not come into play until the main script ends.

Each scripts connects and disconnects from the DB.
Does mssql_free_result() need to be called as well?

You would expect it to - for the time being, you might explicitly free the results and see if it makes a difference. I'll look into the PHP core and see if it does.
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,083
#3: 4 Weeks Ago

re: Freeing memory when using Databases


I have read online articles (sorry no reference) studying PHP and memory de-allocation, and in a lot of cases it does not work as expected.
unset() for example rarely frees up memory immediately and can even increase.

Whereas visual output such as echo is memory hungry.
I am going to try disabling the HTML output when running all scripts together (usually from a schedule task) but allow when run seperately
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,083
#4: 4 Weeks Ago

re: Freeing memory when using Databases


Curious. I used mssql_free_result() at the end of the first script before closing the connection and now no memory overflow problem.

The query returns about 6400 records with 5 fields per record.
Two DATETIME fields, two DECIMAL and one small VARCHAR.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,953
#5: 3 Weeks Ago

re: Freeing memory when using Databases


Quote:

Originally Posted by code green View Post

Curious. I used mssql_free_result() at the end of the first script before closing the connection and now no memory overflow problem.

The query returns about 6400 records with 5 fields per record.
Two DATETIME fields, two DECIMAL and one small VARCHAR.

So no implicit memory freeing. Strange. I'll take this up on the PHP internals list.
Reply