|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Panama Jack Smarty Rookie
Joined: 23 Jun 2003 Posts: 16
|
Posted: Tue Jul 08, 2003 5:41 pm Post subject: Just curious about this... |
|
|
If you have a PHP program that includes a number of files (say 3 for example) and each on of those files creates a smarty object are all three smarty object cleared frpom memory when the main PHP program finishes execution.
example: Main PHP File
Code: |
<?
require ("code1.inc");
require ("code2.inc");
require ("code3.inc");
?>
|
Include file 1
Code: |
<?
$smarty = new Smarty;
$smarty->assign("local_charset", $local_charset);
$smarty->display("header.tpl");
?>
|
Include file 2
Code: |
<?
$smarty = new Smarty;
$smarty->assign("local_charset2", $local_charset2);
$smarty->display("header2.tpl");
?>
|
Include file 3
Code: |
<?
$smarty = new Smarty;
$smarty->assign("local_charset3", $local_charset3);
$smarty->display("header3.tpl");
?>
|
I didn't include all of the setup code as this is just an example.
If you notice there is a new smarty object created three times within the main.php but instead of each object being assigned to three different variables it is assigned to one.
When the second object is assigned to the variable used by the first object is the first object freed from memory or does it sit there without a variable reference to it?
When the main.php is finished executing are the first two objects that do not have variables referencing them left in memory or are they purged?
The reason I ask this is because after some experimentation it SEEMS as though they are left in memory and not deleted when the program that called them finishes executing. On the machine where I have multiples bein executed in a similar manner as indicated above the swap file for that system starts to grow to a point where the web server needs to be reset to clear out the swap file. It doesn't seem to happen if there is a single smarty object referenced across the entire execution of the php file.
Just curious if anyone else has noticed this and if it is a Smarty or PHP problem when it comes to referencing and clearing objects. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Jul 08, 2003 6:00 pm Post subject: |
|
|
what php-version?, what web-server (incl. version)? which operating-system?
in theory all memory used by variables should be freed, when the scope of them is lost. not necessarily immediately, but when php's builtin garbage collector thinks it should. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Jul 08, 2003 7:22 pm Post subject: |
|
|
...also are you using a PHP accelarator? How about sessions? What modules are you loading/using?
One thing to try is to manually free the var (try using unset or set the var = null) at the end of execution and see if that changes the behaviour.
My understanding of PHP var lifetime is a little-bit different than messju's in that I think the GC destroys all instanced vars at the end of a request. The only exception I know of is for mods that manage their own memory/resources in which case explicit destruction must be used (IIRC the SAX parser worked like that). In theory, the situation you describe should not arise. Never-the-less, I have often seen parallels to this--especially on Windows boxes. It is usually not a problem as Apache will typically kill and restart the offending process when it grows to an untenable size. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Jul 08, 2003 7:55 pm Post subject: |
|
|
boots wrote: | My understanding of PHP var lifetime is a little-bit different than messju's in that I think the GC destroys all instanced vars at the end of a request. |
there is no difference, that's what i know about it also.
but i don't know if the the garbage-collector is able to catch all vars. under normal circumstances (a forking webserver like apache) this shouldn't matter (only if you set MaxRequestPerChild to zero (==infinite)) since the rest of the memory is freed when the process dies.
but all this may look different in a threaded web-server environment (thats why i asked about version and os). also: AFAIR there are implementations of mfree that don't return the freed memory-pages to the os. that means the free'd memory can be reused by malloc, but the pages are not freed (and the process-size doesn't shrink) until the process exits.
another factor (as you stated, boots) are of course extensions that are loaded. they may contain (although they shouldn't) memory-management that is invisible to php or php's gc. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|