releasing memory by setting objects to null


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: releasing memory by setting objects to null

  1. #1
    Max Erixon Guest

    releasing memory by setting objects to null


    We are using alot of objects on a couple of jsp pages. Would it improve performance
    to set all these objects to null at the end of the page?

    I know that the garbage collector probably will take care of this but will
    it do it's work easier and faster if you set all the objects to null??

    To improve performance and reduce the load on ASP pages this is very useful.

    Regards,
    Max
    Share on Google+

  2. #2
    Larne Pekowsky Guest

    Re: releasing memory by setting objects to null

    Max Erixon <max.erixon@framfab.se> wrote:

    >We are using alot of objects on a couple of jsp pages. Would it
    >improve performance to set all these objects to null at the end of
    >the page?


    Hi Max,

    To some extent this depends on what version of the Java VM you're
    working with, but as a general rule I wouldn't think this would help
    too much.

    The garbage collector will reallocate space when it can prove that
    there is no reference to that space. So in the following code:


    <% String foo = new String("Hello"); %>

    .... rest of page ...

    <% foo = null; %>


    The string can be freed up as soon as foo is no longer pointer to it.
    However, when the page ends the variable foo will go out of scope
    anyway, at which point there will be no reference to the string left
    and it can be freed.

    Really the best thing you can do on the performance front is move to
    the latest version of the Java VM. Recent versions include a
    'generational garbage collector' which is optimized for dealing with
    lots of small, short-lived objects.

    The only other thing I can suggest is that you limit what you are
    storing in sessions, and try to expire sessions as soon as possible.
    Everything in the session stays in memory, and typically a session may
    last for half an hour after the user has left the site. Most
    application servers will allow you to lower this timeout, or if you
    can make your users log out you can expire the session as soon as they
    do so.

    - Larne
    Share on Google+

Similar Threads

  1. Getting a GUI to run
    By Eric in forum Java
    Replies: 4
    Last Post: 04-14-2006, 09:09 AM
  2. Getting a large number of identities
    By Colin McGuigan in forum Database
    Replies: 12
    Last Post: 04-15-2002, 07:43 AM
  3. Getting a GUI to function
    By Eric in forum Java
    Replies: 1
    Last Post: 11-27-2001, 06:53 AM
  4. help memory
    By kathy in forum Java
    Replies: 0
    Last Post: 11-02-2001, 04:22 PM
  5. Multi-row calculations
    By Bob Hines in forum Database
    Replies: 7
    Last Post: 04-27-2000, 11:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center