Results 1 to 6 of 6

Thread: What is the Garbage Collection in PHP?

  1. #1
    Join Date
    May 2009
    Posts
    201

    What is the Garbage Collection in PHP?

    Hello friends,
    I have recently started with the advanced study of the PHP programming language. Before this I have done some basic coding in PHP. I want to know about the Garbage Collection that is used in PHP. So please explain me what is the Garbage Collection in PHP? Also provide some useful information that is related with the Garbage Collection.!!

  2. #2
    Join Date
    Jul 2006
    Posts
    289

    Re: What is the Garbage Collection in PHP?

    I think that you should know first about the Reference Count, which is the basic thing for the Garbage Collection. So I have tried to describe about the reference count. There are two parameters that control garbage collection: session.gc_maxlifetime and session.gc_probability, both defined in the php.ini file. A PHP variable is stored in a container called a "zval". A zval container contains, besides the variable's type and value, two additional bits of information. The first is called "is_ref" and is a boolean value indicating Whether or not the variable is part of a "reference set".
    Signatures reduce available bandwidth

  3. #3
    Join Date
    Aug 2006
    Posts
    227

    Re: What is the Garbage Collection in PHP?

    A zval container is created when a new variable is created with a constant value. The following coding may be useful for creating the zval :
    PHP Code:
    <?php 
    $a 
    "new string" 
    ?>
    In this case, the new symbol name, a, is created in the current scope, and a new container is created varies with the type string and the new string value.
    I do to dead flowers what people at morgues do to dead people. Suck all the moisture out, dip them in plastic, paint them up pretty and put them in a nice frame.

  4. #4
    Join Date
    Jul 2006
    Posts
    442

    Re: What is the Garbage Collection in PHP?

    A garbage collection process is run when a session is initialized, for example, when you call the session_start( ). You can also increase the reference count of zval. The following coding explains the same :
    PHP Code:
    <?php 
    $a 
    "new string" 
    $b $a 
    xdebug_debug_zval 'a' ); 
    ?>
    The same variable container is linked with both a and b. PHP is smart enough not to copy the actual variable container when it is not necessary. Each session is examined by the garbage collection process, and any sessions that have not been accessed for a specified period of time are removed. Variable Containers get destroyed when the "refcount" reaches zero. The "refcount" gets decreased by one when any symbol linked to the variable container leaves the scope or when unset () is called on a symbol.
    "When they give you ruled paper, write the other way..." J.R.J.

  5. #5
    Join Date
    Aug 2006
    Posts
    235

    Re: What is the Garbage Collection in PHP?

    If you are using the compound types such as array and object, you will feel that the things are getting more complex. So instead of a scalar value, array and object store their properties in a symbol table of their own. Although there is no longer a symbol in any scope pointing to this structure, it can not be cleaned up Because the array element "1" still points to this same array. Because there is no external symbol pointing to it, there is no way for a user to clean up this structure; Thus you get a memory leak. Fortunately, PHP will clean up this data structure at the end of the request, but before then, this is taking up valuable space in memory.
    3.2 (northwood)
    2gig ram
    ATI AIW X800xt 256mb
    Gigabyte GA-8knxp 875p Chipset
    Optiwrite 8X DVD Burner
    Win XP PRO Sp2 (Works Perfectly)
    2 SATA Raptor 74gig Raid 0
    2 7200 IDE 320gig HD

  6. #6
    Join Date
    Mar 2008
    Posts
    672

    Re: What is the Garbage Collection in PHP?

    The garbage collection process can become expensive to run, especially in sites with high numbers of users. When it is important to prevent users from accessing old sessions, the gc_probability should be increased. A garbage collector, whose mission is to free memory that can be typically "harvesting" cyclic references in the variables that are no longer used, and functions "gc_ *" to control it. Normally, with the default configuration, the garbage collector is activated. The Inability to collect cycles is generally Considered to be the greatest weakness of reference counting collectors. It either places the burden on the programmer to break cycles explicitly, or requires special programmingidioms, or requires a tracing collector to collect the rings.

Similar Threads

  1. How to Force Garbage Collection In Java?
    By Sheenas in forum Software Development
    Replies: 6
    Last Post: 28-04-2011, 01:30 PM
  2. JAVA - What is garbage collection
    By Bhim in forum Software Development
    Replies: 5
    Last Post: 28-04-2011, 01:13 PM
  3. Does C Sharp provide automatic garbage collection ?
    By kALAMATHI in forum Software Development
    Replies: 3
    Last Post: 08-01-2011, 08:33 AM
  4. Control the garbage collector
    By Anthony12 in forum Software Development
    Replies: 6
    Last Post: 02-08-2010, 10:32 AM
  5. Java - help with Garbage Collection
    By Messenger in forum Software Development
    Replies: 4
    Last Post: 23-07-2010, 10:18 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,819,823.00149 seconds with 16 queries