unsetting or destroying objects necessary?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TooN

    #1

    unsetting or destroying objects necessary?

    Hi,

    I'm building an application with over 10thousand database entries. I
    was wondering if it would be useful, regarding memory load and server
    performance to unset/destroy objects at the moment when they are no
    longer needed.
    Will this improve performance, or will it not make any difference.

    Thanks for any help.

    TooN
  • Richard Grove

    #2
    Re: unsetting or destroying objects necessary?

    "TooN" <toon@company.c om> wrote in message
    news:1812200313 46399251%toon@c ompany.com...[color=blue]
    > Hi,
    >
    > I'm building an application with over 10thousand database entries. I
    > was wondering if it would be useful, regarding memory load and server
    > performance to unset/destroy objects at the moment when they are no
    > longer needed.
    > Will this improve performance, or will it not make any difference.
    >
    > Thanks for any help.
    >
    > TooN[/color]


    Won't make a great deal of differnece how may entries you have. Unsetting
    variables requires processor power, so if anything, it may even make your
    scripts slower.
    IMHO I wouldn't bother.

    Regards
    Richard Grove

    http://shopbuilder.org - ecommerce systems
    Become a Shop Builder re-seller:
    Affiliate marketing is a simple way to earn money online, using our affiliate platform. Join a global community of publishers and advertisers.

    Affiliate marketing is a simple way to earn money online, using our affiliate platform. Join a global community of publishers and advertisers.






    Comment

    • Pedro Graca

      #3
      Re: unsetting or destroying objects necessary?

      TooN wrote:[color=blue]
      > I'm building an application with over 10thousand database entries. I
      > was wondering if it would be useful, regarding memory load and server
      > performance to unset/destroy objects at the moment when they are no
      > longer needed.
      > Will this improve performance, or will it not make any difference.[/color]

      As another poster said, it probably won't make a big difference;
      however, suppose you grab 50K (too farfetched?) from the database and
      have 200 simultaneous users -- that makes 10M of data loaded into RAM
      while each script is executing ... maybe you'd like to limit that only
      to the parts of the script where it is needed only. Anyway they'll be
      unset when you tell PHP to (with unset()) or at the end of the script.

      I tend to do it for "large" things

      <?php
      // ...
      $res = mysql_query($sq l)
      // deal with it
      unset($res);
      // ...
      ?>

      <?php
      // ...
      $data = file('http://www.example.com/large_page.html ');
      // extract data
      unset($data);
      // ...
      ?>
      --
      --= my mail box only accepts =--
      --= Content-Type: text/plain =--
      --= Size below 10001 bytes =--

      Comment

      • TooN

        #4
        Re: unsetting or destroying objects necessary?

        In article <3fe1a219$0$306 02$65c69314@mer cury.nildram.ne t>, Richard
        Grove wrote:
        [color=blue]
        > "TooN" <toon@company.c om> wrote in message
        > news:1812200313 46399251%toon@c ompany.com...[color=green]
        > > Hi,
        > >
        > > I'm building an application with over 10thousand database entries. I
        > > was wondering if it would be useful, regarding memory load and server
        > > performance to unset/destroy objects at the moment when they are no
        > > longer needed.
        > > Will this improve performance, or will it not make any difference.
        > >
        > > Thanks for any help.
        > >
        > > TooN[/color]
        >
        >
        > Won't make a great deal of differnece how may entries you have. Unsetting
        > variables requires processor power, so if anything, it may even make your
        > scripts slower.
        > IMHO I wouldn't bother.
        >
        > Regards
        > Richard Grove
        >[/color]

        Just what I thought.
        Thanks for answering!

        TooN

        Comment

        • Pedro Graca

          #5
          Re: unsetting or destroying objects necessary?

          I (Pedro Graca) wrote:[color=blue]
          ><?php
          > // ...
          > $res = mysql_query($sq l)
          > // deal with it
          > unset($res);[/color]

          oops ... that should have been
          mysql_free_resu lt($res);[color=blue]
          > // ...
          > ?>[/color]
          --
          --= my mail box only accepts =--
          --= Content-Type: text/plain =--
          --= Size below 10001 bytes =--

          Comment

          • TooN

            #6
            Re: unsetting or destroying objects necessary?

            In article <brs8n4$7382l$1 @ID-203069.news.uni-berlin.de>, Pedro Graca
            <hexkid@hotpop. com> wrote:

            Thanks for thinking along with me,
            although I don't expect 200 simultaneous users, we keep it in mind!

            Toon
            [color=blue]
            >
            > As another poster said, it probably won't make a big difference;
            > however, suppose you grab 50K (too farfetched?) from the database and
            > have 200 simultaneous users -- that makes 10M of data loaded into RAM
            > while each script is executing ... maybe you'd like to limit that only
            > to the parts of the script where it is needed only. Anyway they'll be
            > unset when you tell PHP to (with unset()) or at the end of the script.
            >
            > I tend to do it for "large" things
            >
            > <?php
            > // ...
            > $res = mysql_query($sq l)
            > // deal with it
            > unset($res);
            > // ...
            > ?>
            >
            > <?php
            > // ...
            > $data = file('http://www.example.com/large_page.html ');
            > // extract data
            > unset($data);
            > // ...
            > ?>[/color]

            Comment

            • Nikolai Chuvakhin

              #7
              Re: unsetting or destroying objects necessary?

              TooN <toon@company.c om> wrote in message
              news:<181220031 346399251%toon@ company.com>...[color=blue]
              >
              > I'm building an application with over 10thousand database entries. I
              > was wondering if it would be useful, regarding memory load and server
              > performance to unset/destroy objects at the moment when they are no
              > longer needed.
              > Will this improve performance, or will it not make any difference.[/color]

              Surprise, surprise... Using unset() on an object DOES NOT free up
              any memory in PHP 4. Zurab Davitiani posted his observations on the
              subject to this newsgroup back in October:



              This is expected to be resolved in PHP 5, which implements
              destructors.
              Until then, your best bet for a high-performance memory-intensive
              application is to ban OOP from it (which, in my book, is always a good
              idea to consider when working with PHP. PHP does not run on a virtual
              machine and has no system objects; all calls to OS and other low-level
              software such as database engines are procedural, so there is no need
              to introduce the overhead of OOP, unless you are into refactoring, in
              which case you are simply buying shorter application development time
              with lower application performance).

              Cheers,
              NC

              Comment

              Working...