imagedestroy and similar

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?iso-8859-1?B?QW5kcukgSORuc2Vs?=

    #1

    imagedestroy and similar

    Hi,

    is there a difference between imagedestroy($i h) and unset($ih)?

    The same with other similar functions like closedir, mysql_close,
    curl_close, mysql_free_resu lt, etc.

    And by the way... will the garbage collector even detect an "implicit
    unset" when a resource is used for the last time?

    Regards,
    André

  • Jerry Stuckle

    #2
    Re: imagedestroy and similar

    ljb wrote:
    andre@webkr.de wrote:
    >Hi,
    >>
    >is there a difference between imagedestroy($i h) and unset($ih)?
    >>
    >The same with other similar functions like closedir, mysql_close,
    >curl_close, mysql_free_resu lt, etc.
    >>
    >And by the way... will the garbage collector even detect an "implicit
    >unset" when a resource is used for the last time?
    >
    In the case of GD, I think imagedestroy does nothing more than unset. But
    you probably should not assume that in general. If the resource is properly
    implemented, then yes unsetting it should do all the necessary cleanup.
    >
    The garbage collector does not detect when a resource is used for the last
    time. It does detect when it goes out of scope. For example, a resource
    variable local to a function ... when the function returns, the resource
    should be cleaned up.
    One correction - the gc eventually detects when the resource is no
    longer being used. But such detection is almost always not immediate,
    and may in fact take quite some time.

    It's much better to destroy the resources when you're done with them and
    not leave it up to the gc. Doing the latter is just plain sloppy, lazy
    or both.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • gosha bine

      #3
      Re: imagedestroy and similar

      On 20.04.2007 02:17 André Hänsel wrote:
      Hi,
      >
      is there a difference between imagedestroy($i h) and unset($ih)?
      No. unset() checks if a variable is referenced elsewhere and if not,
      destroys the variable and its value immediately. This is called
      "reference counting".
      >
      The same with other similar functions like closedir, mysql_close,
      curl_close, mysql_free_resu lt, etc.
      Yes, if an extension author took care of registering his destructor in
      zend core.
      >
      And by the way... will the garbage collector even detect an "implicit
      unset" when a resource is used for the last time?
      php doesn't use "garbage collector", memory is reclaimed immediately as
      it becomes inaccesible.
      >
      Regards,
      André
      >

      --
      gosha bine

      extended php parser ~ http://code.google.com/p/pihipi
      blok ~ http://www.tagarga.com/blok

      Comment

      • Jerry Stuckle

        #4
        Re: imagedestroy and similar

        gosha bine wrote:
        On 20.04.2007 02:17 André Hänsel wrote:
        >Hi,
        >>
        >is there a difference between imagedestroy($i h) and unset($ih)?
        >
        No. unset() checks if a variable is referenced elsewhere and if not,
        destroys the variable and its value immediately. This is called
        "reference counting".
        >
        >>
        >The same with other similar functions like closedir, mysql_close,
        >curl_close, mysql_free_resu lt, etc.
        >
        Yes, if an extension author took care of registering his destructor in
        zend core.
        >
        >>
        >And by the way... will the garbage collector even detect an "implicit
        >unset" when a resource is used for the last time?
        >
        php doesn't use "garbage collector", memory is reclaimed immediately as
        it becomes inaccesible.
        >
        >>
        >Regards,
        >André
        >>
        >
        >
        Andre,

        Not completely true.

        Yes, memory is reclaimed immediately when you unset the resource. But if
        you don't unset it before the end of the page, there may be a delay
        before PHP gets around to cleaning things up. It doesn't necessarily do
        it immediately.

        Also, there is a garbage collector for sessions to clean up old session
        files. But that's different.


        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • Jerry Stuckle

          #5
          Re: imagedestroy and similar

          ljb wrote:
          jstucklex@attgl obal.net wrote:
          >ljb wrote:
          >>>...
          >>The garbage collector does not detect when a resource is used for the last
          >>time. It does detect when it goes out of scope. For example, a resource
          >>variable local to a function ... when the function returns, the resource
          >>should be cleaned up.
          >One correction - the gc eventually detects when the resource is no
          >longer being used. But such detection is almost always not immediate,
          >and may in fact take quite some time.
          >
          Just for discussion, is there a case where PHP can "detect when the
          resource is no longer being used" other than when the variable referencing
          the resource goes out of scope? I believe you that there is, but I can't
          think of any.
          >
          Also are you saying that if the resource is a local variable in a function,
          and the function returns, there can be a delay before the resource is
          cleaned up (for example, a database connection is closed)?
          I was referring specifically to when the page completes. Cleanup may
          not be done immediately. I don't know for sure about when a function exits.

          And no, there is no way for PHP to predict if a resource still being
          referenced by a variable is going to be used or not. I'd love it if
          they could - I'd use that to write a program to predict the lottery
          numbers :-)


          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          Working...