Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #1339

Re: Disposing of Objects?

From Lew <lewbloch@gmail.com>
Newsgroups comp.lang.java.help
Subject Re: Disposing of Objects?
Date 2011-11-15 08:17 -0800
Organization http://groups.google.com
Message-ID <14847360.425.1321373842152.JavaMail.geo-discussion-forums@prgt40> (permalink)
References <752b3c45-6455-4f52-8cf8-d2ba7714b51f@p16g2000yqd.googlegroups.com> <j9tv9q$dvi$1@dont-email.me>

Show all headers | View raw


markspace wrote:
> Davej wrote:
>> If I have global objects is it desirable to dispose of them before
>> reinstantiating them? Thanks.
> 
> I'm with Stefan in that I don't think your questions makes a lot of 
> sense.  In some cases, it makes sense to create a new object rather than 
> reuse an old one, but in some cases it doesn't.  It depends; mostly on a 
> lot of things that you haven't shared with us.

Here's an outline of an introduction to a primer on Java's memory allocation model.

Nothing is global, in the sense that there is at least one 'Object' in every Java program, the main class class instance.

Yes, I said, "class class".  For every class ('Foo') there is one class object called 'class' ('Foo.class') that represents the entire class.  The class object for your main class kicks off the whole Java program.

Everything else in the program is either a primitive like 'int' or 'boolean', another class's class instance, or an instance of some class, perhaps the main class itself or 'String' or what-have-you.

That's why there are no true global objects in Java.  Everything belongs to some class or other, or to an instance of some class or other.

But, wait!  Belonging to a class is pretty close to global.  If a class member is 'static', it is accessible at the class level (and only there) without need for an instance.

The next third of your question is whether it's necessary to dispose of such objects.  The answer is the same for objects pointed to by a class or by an instance of a class ('static' or instance member pointers, er, um, I mean "references").

No.  Just make sure there are no pointers left that reference that particular object.

What do you mean by "reinstantiating"?

-- 
Lew

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Disposing of Objects? Davej <galt_57@hotmail.com> - 2011-11-15 06:59 -0800
  Re: Disposing of Objects? markspace <-@.> - 2011-11-15 07:08 -0800
    Re: Disposing of Objects? Lew <lewbloch@gmail.com> - 2011-11-15 08:17 -0800
      Re: Disposing of Objects? Davej <galt_57@hotmail.com> - 2011-11-15 09:56 -0800
        Re: Disposing of Objects? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-11-15 10:10 -0800
          Re: Disposing of Objects? Davej <galt_57@hotmail.com> - 2011-11-15 12:15 -0800
            Re: Disposing of Objects? markspace <-@.> - 2011-11-15 12:51 -0800
        Re: Disposing of Objects? Lew <lewbloch@gmail.com> - 2011-11-15 13:00 -0800
        Re: Disposing of Objects? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-15 21:59 -0500
          Re: Disposing of Objects? markspace <-@.> - 2011-11-15 19:13 -0800
            Re: Disposing of Objects? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-15 22:32 -0500
  Re: Disposing of Objects? Davej <galt_57@hotmail.com> - 2011-11-15 08:08 -0800
    Re: Disposing of Objects? markspace <-@.> - 2011-11-15 08:32 -0800
    Re: Disposing of Objects? Lew <lewbloch@gmail.com> - 2011-11-15 12:57 -0800
  Re: Disposing of Objects? Roedy Green <see_website@mindprod.com.invalid> - 2011-11-16 06:23 -0800

csiph-web