Hello thanks in advance for reading my question.
I use a lot of 1, 2 and 3d arrays in my script and I thought it would be nice for the server if I released the arrays after it's been used?
Here is my code to unset my arrays
FUNCTION unsetArr( $Arr1, $Arr2=FALSE, $Arr3=FALSE )
{
FUNCTION _threeD( $Arg ){
FOREACH( $Arg AS $Key => $Value ) {
IF(!is_array($Value)) unset( $Arg[$Key] ); ELSE die('UnsetArr only accept 3D Arrays');
}
}
FUNCTION _twoD( $Arg ){
FOREACH( $Arg AS $Key => $Value ) {
IF(!is_array($Value)) unset( $Arg[$Key] ); ELSE _threeD( $Value );
}
}
FUNCTION _oneD( $Arg ){
FOREACH( $Arg AS $Key => $Value ){
IF(!is_array($Value)) unset( $Arg[$Key] ); ELSE _twoD( $Value );
}
}
$Mem['Pre'] = memory_get_usage();
IF( is_array( $Arr1 ) )
_oneD( $Arr1 );
IF( is_array( $Arr2 ) )
_oneD( $Arr2 );
IF( is_array( $Arr3 ) )
_oneD( $Arr2 );
$Mem['Post'] = memory_get_usage();
RETURN $Mem;
}
Basically it allows me to unset single or multi dimensional arrays and up to 3 arrays at a time.
I thought that it would release memory back to the OS, but it seems to actually consume more memory?
The above when run outputs the following with print_r
Array ( [Pre] => 1619184 [Post] => 1627072 )
So how can my post be greater than my pre when I should have release memory back to the system by unsetting a large number of vars.
In this case I have a huge lang set and page array at the end of my script where I do
/*
* Close Data Base Connection
* CLOSE DB IF NOT USING PCONNECT USE PCON ON DETICATED SERVERS
*/
IF ( !DB_PCON ) mysql_close( $MySQL->link );
$memArr = unsetArr($PageArr, $Lang);
print_r($memArr);
/*
* Template Engine Page Output!
*/
IF ( !strstr( $PageArr['te_tpl_body'], '_page_') ) {
$TE->parse('HEAD', 'header');
$TE->parse('BODY', 'body');
$TE->parse('FOOT', 'footer');
$TE->FastPrint('HEAD');
$TE->FastPrint('BODY');
$TE->FastPrint('FOOT');
}ELSE{
$TE->parse('PAGE', 'page');
$TE->FastPrint('PAGE');
}
$TE->showDebugInfo( $ShowDebug );